Code inspection: Unused local variable
This inspection detects local variables in a method that are declared and may be assigned, but are never used. Such a variable might act only once as the recipient in an assignment statement, without read usages, for example:
Unused variables impair readability of the code, especially in longer functions. Anyone who reads this code will take some time to understand what is the purpose of a variable and why it was assigned a specific value, only to find out that the variable is never read and does not affect the program in any way. Therefore, you should either actually use variables or remove them. ReSharper suggests removing all detected unused variables with a quick-fix.
ReSharper also offers an additional quick-fix — Indicate unused variable with name. You can select a meaningful name for it (_
, dummy
, or unused
), to indicate that the variable is unused deliberately. With these names, ReSharper will not highlight the variable as unused.