views:

446

answers:

4

I've just installed resharper and it's letting me know the namespaces i'm not actually using in each of my classes.

which lead me to the question - is there actually any overhead in leaving these, unused, using declarations in?

is it just a matter of tight code, or is there a performance hit in invoking these namespaces when i don't need to?

+16  A: 

From The C# Team's answers to frequently asked questions:

When you add assembly references or make use of the 'using' keyword, csc.exe will ignore any assembly which you have not actually made use of in your code ... Don't [waste] your time stripping out unused 'using' statements or assembly references from your application. The C# compiler will do so for you automatically.

You can verify that this is actually the case by calling Assembly.GetReferencedAssemblies(); you'll see that anything that isn't used won't actually be included in the list.

The main utility in stripping out unused ones is

  • It is easier to see what your code is actually using
  • It will keep your Intellisense from being polluted with things that you aren't actually going to use.
Daniel LeCheminant
+7  A: 

There are some performance reasons to strip down using statements:

  • VS's IntelliSense runs faster when there is less data to look through

However, note all these reasons are compile-time specific. The compiler strips unused usings automatically.

strager
+1 for the intellisense comment; that's a good point ;]
Daniel LeCheminant
Note to anyone: feel free to add your own points. This is a CW answer. (I won't farm rep. ;P)
strager
+3  A: 

The biggest "overhead" in unusesd using statements is understanding your code :)

Removing unused ones makes your code tidier and easier for somebody else to read and maintain.

Craig Shearer
+2  A: 

The C# code editor in Visual Studio 2008 has a feature to remove unused using statements.

Right-click and select Organize Usings | Remove Unused Usings.

Rob Windsor
grand - that works a treat.
nailitdown