Organize Usings

by Jon Sagara Sunday, August 24 2008 12:09 PM

In Visual Studio 2008, when you add a new Web form to your project, the "using" section of the code-behind contains a lot noise:

using System;

using System.Collections;

using System.Configuration;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Linq;

You may very well need some of those namespace declarations, but odds are high that you don't need them all.  But which ones can you remove without breaking your page?

Visual Studio has a nice feature called Organize Usings, which you access by right-clicking anywhere in the code-behind page.  The menu looks like this:

When you click on "Remove and Sort", it removes any unused "using"s and sorts those that remain. 

So now, instead of the mess that we had before, we have a much cleaner "using" section in our source code file:

using System;

Pretty slick, huh?

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

Blog

Comments are closed

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen

About the author

Jon Sagara develops ASP.NET Web applications in Sacramento, CA.