开发者

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

This question already has answers here: Closed 12 years ago.

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;                 
开发者_C百科}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜