views:

158

answers:

4

Should I use this.

Imports System.IO

Dim myStream As New Stream

or this..

Dim myStream As New System.IO.Stream

Does it make any difference to performance / memory usage?

+3  A: 

No difference whatsoever - it's just a matter of taste and affects readability only.

By the way, CLR is not even aware of the concept of "namespaces": namespace names become prefixes to type names.

Anton Gogolev
Exactly, namespaces are just to save our fingers from extra typing and to differentiate when naming conflicts occur within a project.
Chris Ballance
+1  A: 

In VB.Net you have a third option:

Dim myStream As New IO.Stream

You can't do that in C#. For the IO namespace I almost always use that shortcut, since "IO." isn't that much extra to type. For most other namespaces I tend to add a using statement at the top of the file.

Joel Coehoorn
You can do this in c# 3 with "var myStream = new IO.Stream();"
Andrew Hare
Can you? I'll have to go check at home tonight (only have .Net 2.0 here at work). I know that with 2.0 this just isn't possible in C#.
Joel Coehoorn
+1  A: 

What is more readable to you? I always find it best to import the namespace you need so that you type names are shorter in your code.

Namespaces have no effect on memory or performance - they simply exist to prevent ambiguity between types in a global space.

Andrew Hare
A: 

Thanks muchly. Tis what I thought, but always good to get a second opinion.

Paul,

Paul