Home >Backend Development >C++ >Should C# `using` Directives Be Placed Before or After Namespace Declarations?
C#
The instruction should be placed before or after the name space declaration?
using
STYLECOP insists on putting instructions in the name space, which triggers the issue of potential technology impact. Understanding this slight difference can significantly improve the maintenance of the code.
If instructions are placed outside the naming space, as shown in the following example: using
File2.cs introduced a conflict named space statement: using
<code class="language-csharp">// File1.cs using System; namespace Outer.Inner { // ... }</code>The compiler will give priority to the innermost name space (File2) instead of
instructions, resulting in potential errors.
<code class="language-csharp">// File2.cs namespace Outer { // ... }</code>But by putting the instruction in the name space, as shown below:
using
using
It is worth noting that when the type is defined in the outer name space, not in the outer.inner, no matter what the
<code class="language-csharp">// File1b.cs namespace Outer.Inner { using System; // ... }</code>
The above is the detailed content of Should C# `using` Directives Be Placed Before or After Namespace Declarations?. For more information, please follow other related articles on the PHP Chinese website!