Partager via


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: VS2008Tip

Comments

  • Anonymous
    June 23, 2008
    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.

  • Anonymous
    June 26, 2008
    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 ?

  • Anonymous
    July 09, 2008
    Zack: There are no default shortcuts for these, but you can add your own. Go to the "ToolsOptions..." menu option, and open up the "EnvironmentKeyboard" options page. The commands are: Edit.SortUsings Edit.RemoveUnusedUsings Edit.RemoveAndSort -Tom MSFT, C# IDE

  • Anonymous
    July 09, 2008
    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