views:

50

answers:

2

I have seen that you can either do

using System.IO

and use

Path.GetDirectoryName(blah blah)

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 :)

+5  A: 

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.

Jon Skeet
And even if they didn't, chances are it'd still be a better idea to aim for whichever is easier to read (and thus more maintainable) rather than worry about whatever teensy performance gain might be found.
Amber
+3  A: 

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.

drharris
Aha! So i thought static classes are preloaded! :D
Ranhiru Cooray
Well, I should have been more clear. The classes you actually use will be preloaded, but not all static classes in the namespaces you use are preloaded. There is no guarantee as to when they will actually be loaded, except they always be loaded before you actually use it for the first time.
drharris