是什么在拆卸和/或排序Usings的价值? [英] What's the value in removing and/or sorting Usings?

查看:222
本文介绍了是什么在拆卸和/或排序Usings的价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直运行的删除和排序Usings 的作为理所当然的事,因为它似乎做正确的事。 ?
,而刚才我到想:我们为什么这样做。

I've always run Remove and Sort Usings as a matter of course, because it seems the right thing to do. But just now I got to wondering: Why do we do this?

当然,总有一个清洁和放大器的利益;紧凑的代码。
和必须有一些好处,如果MS拿了把它作为VS菜单项时

Certainly, there's always a benefit to clean & compact code. And there must be some benefit if MS took the time to have it as a menu item in VS.

谁能回答:为什么要这样做呢?
哪些编译时或运行时(或其他方式)的拆卸和/或排序usings好处?

Can anyone answer: why do this? What are the compile-time or run-time (or other) benefits from removing and/or sorting usings?

推荐答案

由于@克雷格-W提到,有一个非常小的编译时的性能改进。

As @craig-w mentions, there's a very small compile time performance improvement.

的方式,编译器作品,当它遇到一个类型,它会在当前的命名空间,然后开始用的顺序使用指令提出,直到它找到它寻找的类型搜索每个命名空间。

The way that the compiler works, is when it encounters a type, it looks in the current namespace, and then starts searching each namespace with a using directive in the order presented until it finds the type it's looking for.

有关于这个极好的书面记录在本书的 CLR通过C#的由杰弗里里希特( HTTP://www.amazon。 COM / CLR-通过-4-开发-参考/ DP / 0735667454 / REF = sr_1_1即= UTF8&放大器; QID = 1417806042&安培; SR = 8-1安培;关键词= CLR +通过+ C%23

There's an excellent writeup on this in the book CLR Via C# by Jeffrey Richter (http://www.amazon.com/CLR-via-4th-Developer-Reference/dp/0735667454/ref=sr_1_1?ie=UTF8&qid=1417806042&sr=8-1&keywords=clr+via+c%23)

至于为什么MS提供的菜单选项,我会想象足够的内部开发人员要求它为你提到同样的原因:更清洁,更简洁的代码

As to why MS provided the menu option, I would imagine that enough internal developers were asking for it for the same reasons that you mention: cleaner, more concise code.

这篇关于是什么在拆卸和/或排序Usings的价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆