C#使用命名空间语句排序

发布于 2024-11-18 12:04:26 字数 87 浏览 3 评论 0原文

我想我在某处读到,排序你的 using 语句并删除未使用的语句会带来某种性能优势......但我似乎找不到任何证据或资源来支持这一点......这有什么道理吗?

I thought I read somewhere that ordering your using statements and getting rid of unused ones had some kind of performance benefit...but I can't seem to find any evidence or resources to support that...is there any truth to this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

走野 2024-11-25 12:04:26

不会,用于设置命名空间的 using 语句没有性能成本。无论语句的顺序如何,生成的 IL 代码都将相同。唯一的优点是清晰度和可读性。此外,删除未使用的会加快编译时间,但运行时性能不会有任何不同。

No, the using statement, for setting the namespaces, has no performance cost. The IL code produced will be the same, regardless of the order of the statements. The only advantage would be for clarity and readability. Also, removing unused ones would speed up compilation time, but run time performance won't be any different.

甜柠檬 2024-11-25 12:04:26

来自 msdn ,

使用命名空间指令
相同的编译单元或命名空间
体互不影响,可以
以任意顺序书写。

您非常想要有用的链接来参观。

From the msdn,

using-namespace-directives in the
same compilation unit or namespace
body do not affect each other and can
be written in any order.

Very much useful link you would like to visit.

别再吹冷风 2024-11-25 12:04:26

其他评论者未提及的另一个问题:您的 using 语句会影响 Intellisense 中显示的内容(特别是扩展方法)。删除未使用的语句将使您的 Intellisense 性能更好,并且仅显示相关的扩展方法。

An additional issue not mentioned by other commenters: Your using statements affect what appears in Intellisense (particular for extension methods). Removing unused statements will keep your Intellisense performing better and only showing relevant extension methods.

美胚控场 2024-11-25 12:04:26

不会有的。至少在运行时肯定不是。在构建时可能需要一些额外的时间来处理它们,但这并不明显。 using 语句不会转移到 IL 代码中,所有内容都有其全名,因此它只是构建时的事情。

现在,就我个人而言,我热键“排序并删除使用”并不断点击它,只是因为它使代码保持干净。但这只是一种强迫症:)

There would not be. At least certainly not at runtime. It is possible that at build time it takes some extra time to process them, but it wouldn't be noticable. The using statements aren't carried over into the IL code, everything has its full name instead, so it is only a build-time thing.

Now, personally, I hot-key "sort and remove usings" and hit it constantly, just because it keeps the code cleaner. But it is just an obsessive-compulsive thing :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文