. . . .


Using .Net usings...

posted 18 August 2010
In .Net to make use of other namespaces (libraries of classes) you do so by the 'using' keyword. On the other hand you can fully qualify the namespace if you wish to avoid including 'using' methodology. Whatever the case this isn't a lesson on the using keyword.

The real point of this post is to attempt a practical ordering included namespaces for all classes. The pattern I'm suggesting (hell, maybe it's even actual recommendation already?) is the following:

(Core namespaces)

(Your [company/project/school] namespace)

(3rd Party namespace)

Essentially giving organization to something that is usually a mess.

Lets take a peek at an example.


using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.IO;
using Dundas.Charting.WebControl;
using MyCompany.Core.Framework;
using MyCompany.Core.Utils;
using MyCompany.Project.Common.Analytics;
using MyCompany.Project.Common.Utils;
using MyCompany.Project.Core.Emissary;


Look at this mess, no order, its not immediately obvious which 3rd party components are being used.

Now using my suggestion:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.IO;

using MyCompany.Core.Framework;
using MyCompany.Core.Utils;
using MyCompany.Project.Common.Analytics;
using MyCompany.Project.Common.Utils;
using MyCompany.Project.Core.Emissary;

using Dundas.Charting.WebControl;


Doesn't that look better? It gets across everything immediately and in an standard fashion.

Oh also, always always always get rid of unused namespaces. More clutter to junk up your files.

Quick easy fashion to do this. Right click on your class definition -> Organize Usings -> Remove and Sort. Now there is no excuse to have unordered, non-used namespaces in your files, and its built in.