views:

519

answers:

6

Is there a tool available that can scan a C# or VB.NET project and automatically remove all unused local variables?

+3  A: 

You can use ReSharper. It will mark all unused variables and allow you to remove them.

Anton
A: 

You can use FxCop to analyse your code.

Our you van install resharper that greys unused local variables out

With both tools you have to delete them your self

Ivo
Well, not exactly. ReSharper will not only hightlight the variables; it will also provide you the command to remove them one at a time.
John Saunders
Ah, didnt know that :) Thanks
Ivo
A: 

It looks like ReSharper should help you clean up your code.

Bryan Denny
+11  A: 

Ahem: FxCop and ReSharper are nice and all, but the compiler will happily ignore unused variables and never even declare them in compiled code if you enable the optimize option.

Randolpho
+1 Much better answer
Josh Stodola
local variables can be ignored by the compiler, but they might hinder readability of the code by other human developers. depends of course on the code and how complex/ordered/commented it is.
Ami
A: 

Visual Studio Team System (Code analysis), will also let you know about unused variables, but will not remove them. I feel you should just write clean code. chances are if you can't do that, you have other problems.

eschneider
A: 

FxCop is a useful tool in a number of ways, one of which is that it will point out unused variables and parameters. This is helpful if you have your code going through a continuous integration process.

ReSharper will highlight unused variables and parameters when you are in Visual Studio.

Neither tool will automatically do the removal for you, although it's usually a simple thing to do...R# even provides a shortcut command to remove a single selected variable for you.

Grant Palin