Is there a tool available that can scan a C# or VB.NET project and automatically remove all unused local variables?
You can use ReSharper. It will mark all unused variables and allow you to remove them.
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.
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).
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.
You can use ReSharper. It will mark all unused variables and allow you to remove them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With