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?
-
Sounds false to me. Order them in what way, anyway? – Brad Jul 01 '11 at 02:49
-
The only impact it could have on performance is that of Visual Studio's intellisense, but that isn't usually an issue with VS 2010 & a modern PC. Types are all bound at compile time, so usings don't effect runtime performance (see the answer from @keyboardP about IL code). – Paul Wheeler Jul 01 '11 at 02:57
-
well I don't remember where I heard or read it...or maybe I'm confusing something else...it seemed that the logic was if you ordered them somehow, they would get loaded into memory such that it would be more efficient and maybe even quicker...like defragging your namespaces or something...I dunno :) obviously, the reason I couldn't find anything on google about it is becauzse it's apparently pure fiction :) – J Benjamin Jul 05 '11 at 18:59
4 Answers
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.

- 68,824
- 13
- 156
- 205
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.

- 1
- 1

- 53,625
- 36
- 139
- 164
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.

- 25,252
- 29
- 125
- 205
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 :)

- 42,906
- 18
- 101
- 138
-
I was thinking earlier today it would be nice if you only had to specify using statements for ambiguous types. So I wouldn't have to specify `using System;` to access `String`, etc :-) – CodeNaked Jul 01 '11 at 02:54