Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using statements before or after Namespace in C# [duplicate]

Tags:

namespaces

c#

Possible Duplicate:
Should Usings be inside or outside the namespace

So there are two approaches to where you have your using statements in regard to the namespace. You can either have them outside the namespace declaration or inside. What is the pro/con between the two approaches and which is generally preferred.

using System;

namespace MyNamespace
{
}

or:

namespace MyNamespace
{    
      using System;                 
}
like image 336
Kenoyer130 Avatar asked Oct 14 '10 19:10

Kenoyer130


1 Answers

I typically see the former in use. These using statements are typically at the very top of a source file, making it easy to see at a glance what a particular file makes use of. It also allows you to easily see the start of new code, as the namespace signals the new stuff.

The other way is a little bit less easy to follow from an organizational standpoint. The only benefit is that you could have different using statements in two different namespaces in the same file, but using two namespaces in the same place like that is bad coding practice, so it should be avoided.

like image 64
Wade Tandy Avatar answered Oct 12 '22 23:10

Wade Tandy