Possible Duplicate:
Using Statements vs Namespace path? C#
I just want to know what the difference between including the namespace at the top of a C# class vs actually defining it in the program code.
So:
using System.Windows;
Or
System.Windows.MessageBox.Show();
Would having the namespace load the whole library or will only the needed data be used?
Sorry if it may seem confusing.
You need to distinguish between namespaces and assemblies. They're very different things.
using
directives only talk about namespaces - and the two ways of referring to MessageBox
will produce exactly the same code. Use whichever produces the most readable code - which is usually to use using
directives and short names.
The first is easier to read. You should favour readability. I don't think there is a compilation or loading benefit either way and if there is I haven't noticed it on 500kloc projects.
Write the full namespace directly in your statements if some identifier is ambiguous.
using System.Windows.Forms;
using System.ServiceModel.Channels;
...
var msg = new Message(); // ambiguous
var msg1 = new System.Windows.Forms.Message(); // OK
var msg2 = new System.ServiceModel.Channels.Message(); // OK