开发者

vs using [namespace.x.xx]?

I have seen that you can either do

using System.IO

and use

Path.GetDirectoryName(blah blah)
开发者_JAVA百科

OR directly use

System.IO.Path.GetDirectoryName(blah blah);

Is there any difference between them from a point of performance?

Does using System.IO loads all static classes in the namespace to the memory resulting in using more memory or is the framework is intelligent enough to avoid that? If yes, how?

Or is this all just used to avoid naming collisions between objects across namespaces?

Any insight would be greatly appreciated :)


No, they compile to the same IL. It's purely a matter of the source code - it's generally more readable to use the short name rather than the fully qualified one.

The compilation results will be identical either way.


If you look at the IL, there is no difference in the two methods. All class names are fully qualified. Static classes are only loaded when the class is first used. So, both methods are equivalent in the final code.

In addition, I find it much more helpful to browse the using declarations to see what the class is doing in terms of things external to the class (for example, is the class performing I/O or generating XML). This, as opposed to always declaring fully qualified class names.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜