bitbonk bitbonk - 1 year ago 132
C# Question

resharper "cleanup code" vs. 'var' keyword

I have an odd behavior with code clean up for c# in visual studio 2008 Team Developer Edition.

Whenever I clean up my code using "Full Cleanup", it replaces all variables declaration with explicit type declarations. But I have set the appropriate settings under "Inspection Severity", "Use var keyword when initializer explicitly declares type" and "use var keyword when possible" to "Show as Error"

Is there any other setting I need to set or is this a known bug?

Answer Source

There's a setting under the Code Cleanup section that specifies what Code Cleanup should do with var declarations.

In the ReSharper Menu, select Options. At the bottom of the tree view, select Code Cleanup (in the Tools section). Select a Code Cleanup preset on the right, and then look at the Use 'var' in declaration setting. You probably want the Replace direction setting set to Do not change.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download