I have a VB file that imports System.IO, but only uses it is a couple of places. My co-workers and I were wondering if there is a small performance boost if we just use System.IO explicitly were we need it (IE., System.IO.MemoryStream) instead of importing it.
views:
51answers:
2No. There's no difference. The compiler produces exactly the same IL in either case.
You can prove it by compiling it both ways, and then using Reflector to disassemble the assembly and observe the IL produced.
Robert is exactly correct. I'll add that the purpose of importing namespaces (VB.NET is Imports
; C# is using
) is to avoid having to type the fully-qualified name of every class that you intend to consume. The compiled IL code still uses the fully qualified name, so importing the namespace is just there to simplify some of your work as a developer.
One drawback with importing namespaces is that if someone gives you code to use, but doesn't share with you the top of their code file with the namespace imports, you have to figure out for yourself what namespace to add.