.NET命名空间和使用说明 [英] .NET namespaces and using statements
问题描述
可能重复:
<一href="http://stackoverflow.com/questions/125319/should-usings-be-inside-or-outside-the-namespace">Should Usings的内部或命名空间外
namespace x
{
using y;
}
和
using y;
namespace x
{
}
推荐答案
第一种具有的y范围只是命名空间X,第二个有Ÿ范围为整个文件,所以potentialy其他名称空间。如果你把每个文件的一个命名空间(我猜是这样的约定)再有就是的一般的没有真正的区别[但见马克的评论有关冲突如果不同的类型具有相同的名称在不同的命名空间。如果你使用了StyleCop它会要你保持usings命名空间内。
The first one has y in scope for just the namespace x, the second has y in scope for the whole file, so potentialy other namespaces. If you keep to one namespace per file (I'd guess that was the convention) then there's usually no real difference [but see Marc's comment about clashes if different types have the same name in different namespaces]. If you use StyleCop it will want you to keep the usings inside the namespace.
这篇关于.NET命名空间和使用说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!