Rajesh kumar’s Blog

If you have knowledge, let others light their candles at it.

  • Author

  • Rajesh Tweets

    Error: Twitter did not respond. Please wait a few minutes and refresh this page.

  • Enter your email address to follow this blog and receive notifications of new posts by email.

    Join 2 other followers

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 Structure

Default Class StructureContext menu in Visual Studio

 

Context menu in Visual Studio

Context menu in Visual Studio

Class structure after Removing and Sorting unused namespaces

Class structure after Removing and Sorting unused namespaces

This is a very cool and useful feature 🙂

Advertisements

2 Responses to “Remove unused namespaces from Visual Studio”

  1. 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 🙂

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: