Is there a general rule for referencing a type from a different namespace. Do you consistently use :
using System.Drawing;
instead of defining it when needed:
System.Drawing.Graphics gr;
I tend to type the full namespace when I'm only "calling" it once. Is there any best practice about that ?
What I use, (and what I believe most developers use), is to always say
using System.Drawing;
and reserve
System.Drawing.Graphics gr;
only for places where there is a conflict with there being two Graphics
defined in different namespaces, and, even then, I'll still rather use a using
to differentiate them:
using MyGraphics=My.Own.Conflicting.Named.Graphics;
// :
var myGraph = new MyGraphics();
Fully qualified names in code are distracting and noisy. I prefer to never have them. If there is a namespace conflict, a using alias can resolve that.
Besides, let's face it, 99.99% of us C# developers are using Visual Studio, so knowing what namespace and/or assembly a type is coming from is as quick as F12 or just hovering the mouse for a second.
The only time I like fully qualified names in code is in code samples, like here on Stack Overflow, to make it clear exactly what type is being used.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With