Last post Feb 28, 2006 06:29 PM by cniknet
Feb 28, 2006 04:17 PM|Oyster|LINK
Just wondering about the following and hope someone could quickly clarify.
In regard to the importation of namespaces for module development, is there an significance on how you do it?
For example can you just import the required namespaces at project level or just import them at control level?
Is there any overhead for importing at project level in situations were only some of your controls require the namespace?
Does it just come down to personal preference?
Thanks in advance.. :-)
Feb 28, 2006 06:29 PM|cniknet|LINK
As a general rule, be frugal about the namespaces you reference in any .Net project, limiting references to only those being used. By only referencing namespaces you are actually using, your code's dependencies are clear, the compiler has to do a little
less work and you make your code impervious to changes in an assembly that you have referenced, but don't actually use for anything in your code, especially if the assembly is strong-named.
My personal preference is to only import Microsoft.VisualBasic at the project level and import all other namespaces in individual class files as needed. This may be a bit extreme, but it works for me and keeps things consistent regardless of whether I am
developing in VB.Net or C#.
I also make it a point never to include any namespaces within the code because it makes code harder to maintain (sort of the same reason why it's not a good idea to use absolute URL references in an HTML page). VS.Net annoyingly puts these everywhere, but
thankfully it has the ALT-Drag feature that allows you to highlight a column of text and hit delete to get rid of many rows of "System.Web.UI.WebControls." at one shot.