#758 – Cleaning Up using Directives in a File

You use using directives at the top of a file to bring various namespaces into scope, so that you don’t need to fully qualify named members within those namespaces.

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

Extra using directives don’t hurt anything–the list of directives is just a list of possible namespaces to consult when resolving a name.  Your code may not actually reference members in all of the listed namespaces.

For cosmetic purposes, however, there is an easy command in Visual Studio that you can use to clean up using directives for namespaces that you don’t use.

To remove unused namespaces, you can right-click in the source code editor and select Organize Usings and then Remove Unused Usings.  After you do this, you’ll be left only with namespaces that contain members that your code contains.

758-001

 

758-002

Advertisements

About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

One Response to #758 – Cleaning Up using Directives in a File

  1. A bit of caution here, if you have code in conditional directives (i.e. #if DEBUG), and it’s not defined when you use this feature, Visual Studio will gladly remove using directives that it depends on.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: