Welcome to MSDN Blogs Sign in | Join | Help

Sara Ford's Weblog

My adventures embracing open source on CodePlex and at Microsoft

News

    • Did you know... All author proceeds go directly to sending Hurricane Katrina survivors to college.

      Microsoft Visual Studio Tips book

      Recent Entries

Did you know… Remove unused using statements? - #240

This was tip #17 in my TechEd VS 2008 IDE Tips and Tricks Talk

In C#, there’s the option to remove any of your unused using statements.  This is especially helpful if you’re reusing some sort of template over and over again.  Instead of having to comment out each line, compile, see whether the compile was successful, then either remove or uncomment the line, you can bring up the editor context menu (just right click in the editor), and choose Organize Usings - Remove Unused Usings.  This will do all the hard work for you.

RemoveUnusedUsings

Technorati Tags:
Posted: Wednesday, June 18, 2008 3:00 AM by saraford

Comments

Zack Owens said:

Is there a key combo for this? It would be nice if I could, say, click Alt + ctr + f10 or something cool. Just a thought.

# June 24, 2008 12:25 AM

fars1d3r said:

In addition to removing the unused Usings you can also Sort them - is there any good reason to sort them ?  Does it improve performance on compiles or object loading or is just prettier ?

# June 26, 2008 4:57 PM

Tom Meschter (MS) said:

Zack:

There are no default shortcuts for these, but you can add your own. Go to the "Tools\Options..." menu option, and open up the "Environment\Keyboard" options page.

The commands are:

Edit.SortUsings

Edit.RemoveUnusedUsings

Edit.RemoveAndSort

-Tom

MSFT, C# IDE

# July 9, 2008 5:46 PM

Tom Meschter (MS) said:

fars1d3r:

Sorting the usings doesn't do anything but make them easier to look through. As it will effectively group related namespaces (e.g., all the System.* namespaces will end up next to each other) it can make it much easier to scan through a long list of "usings".

-Tom

MSFT, C# IDE

# July 9, 2008 5:50 PM
New Comments to this post are disabled
Page view tracker