Resharper Local Variable is never used
Okay, I have a problem with Resharper that is driving me nuts. Let's say I create a method such as
private int returnAValue(string something)
{
int dmid;
}
As I'm typing the method Resharper take the variable dmid 开发者_StackOverflowand declares that it is a 'Local Variable that is never used'. As a result it changes the coloring of the text. How can I suppress this?
Simply ignore that sort of warning until you've actually written enough code to care. In my experience that's usually not long after the declaration, assuming you're declaring variables as late as you can (which I consider to be a good idea). While the code is still being typed, it's unlikely to even compile...
If you have finished the method and you've still got the warning, then it's absolutely right - you should get rid of the unused variable.
Type faster (and/or have a bigger solution) - then you'll beat R# and use the variable before it's highlighted. ;)
FWIW, I don't use R# - but surely they have an option to disable that check? Let the compiler catch it as a warning if you like, but then it'd only flag it on build.
I use resharper 4.5; thou I don't recommend turning this littler warning helper off I believe you can change the setting by following this path in Visual Studio. ReSharper -> Options -> Code Inspection -> Inspection Severity then look in the Potential Errors and Bad Practices. Hope that helps.
You can suppress this warning for a single line using a comment:
// ReSharper disable once UnusedVariable.Compiler
int dmid;
Resharper can generate this for you automatically. In Resharper v8.2.3 you press Alt+Enter on the offending variable, then choose 'Options for "Unused local variable" inspection'. You will be offered various options to suppress or disable this warning. The comment above was generated by choosing "Disable once with comment".
精彩评论