Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing unused local variables from .NET code

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

like image 690
Jesse MacVicar Avatar asked Mar 22 '10 13:03

Jesse MacVicar


People also ask

How do you delete unused variables in Visual Studio?

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

What does unused local variable mean in Visual Basic?

Unused local variable: '<localvariablename>'A local variable in a procedure is declared but never used. One possibility is that there is a spelling mistake among the local variables in the procedure.

How do I remove unused variables in Eclipse?

You can delete all unused variables of a selected area: Open the source code editor of the development object. Select the code where you want to delete the unused variables. From the context menu, choose Source > Delete Unused Variables (Selection) (Ctrl + Shift U).


2 Answers

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.

like image 174
Randolpho Avatar answered Sep 28 '22 05:09

Randolpho


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

like image 21
Anton Avatar answered Sep 28 '22 05:09

Anton