JetBrains Rider 2024.1 Help

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:

public string ConvertValue(string newValue) { string s = newValue.ToLower(); // unused local variable return newValue.ToLower(); }

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. JetBrains Rider suggests removing all detected unused variables with a quick-fix.

JetBrains Rider 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, JetBrains Rider will not highlight the variable as unused.

Last modified: 11 February 2024