C# sa1200 是否所有 using 指令都必须放在命名空间(StyleCop)内纯粹是装饰性的?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1071797/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 07:33:40  来源:igfitidea点击:

Is sa1200 All using directives must be placed inside the namespace (StyleCop) purely cosmetic?

c#stylecop

提问by Matt

Possible Duplicate:
Should Usings be inside or outside the namespace

可能的重复:
Usings 应该在命名空间内部还是外部

sa1200 All using directives must be placed inside the namespace (StyleCop)

sa1200 所有 using 指令都必须放在命名空间内 (StyleCop)

Is this just for code readibility or is there any actual advantage to doing so? Does it help the GC somehow?

这只是为了代码可读性还是这样做有什么实际好处?它以某种方式帮助GC吗?

回答by Reed Copsey

There is no runtime difference. It's purely a compile time (and development experience) change. The file, compiled IL will be identical in either case.

没有运行时差异。这纯粹是编译时(和开发经验)的变化。在任何一种情况下,编译的 IL 文件都是相同的。

回答by Brad Bruce

If you have multiple namespaces in your project, you can limit which namespaces are used by each one individually.

如果您的项目中有多个命名空间,您可以限制每个命名空间单独使用哪些命名空间。

This might come in handy if there were class names in two different namespaces that were the same. One might be the default in one part of your project, while the other could be the default in another.

如果两个不同的命名空间中有相同的类名,这可能会派上用场。一个可能是项目某一部分的默认值,而另一个可能是另一部分的默认值。

Yes they look for some really fringe cases for these rules.

是的,他们为这些规则寻找一些非常边缘的案例。