Remove unused namespaces from Visual Studio
Posted by Rajesh Kumar on August 12, 2009
When we add any new class file, Visual Studio 2008 by default adds few namespaces depending on the project type. But, in real time – we will not be using one or all of the namespaces.
At the same time, most of us know only few namespace of the objects that we are going to use. So, it is a bit difficult to identify and remove the namespace. So, how can we make the code clean?
Fortunately, Visual Studio allows to Sort, Remove and Remove & Sort unused namespaces. The following pictures shows you how the class file looks like before and after removing the unused namespaces:

Default Class StructureContext menu in Visual Studio

Context menu in Visual Studio

Class structure after Removing and Sorting unused namespaces
This is a very cool and useful feature
Daniel.Dority said
Even though it is a waste having namespaces that aren’t being utilitized in the code, at compile time the compiler checks that for you and includes it when it exists. It also removes the reference if it doesn’t.
Rajesh Kumar said
Hi Daniel,
Thank you for your comment. I have updated the article. It still a good idea to use this feature to make the code clean