ReSharper
 
Get ReSharper
Get your hands on the new features ahead of the release by joining the Early Access Program for ReSharper 2025.1! Learn more

Code inspection: Potentially misleading parameter name in lambda or local function

Last modified: 14 May 2024

Historically, the symbol _ has been a valid identifier name in C#, making it perfectly legal to name variables, parameters, and other code entities as _. However, with the introduction of the discards concept in C#, using _ as a name has become undesirable, as it can block the usage of _ to express the value discard in some scope of code.

As C# gradually moves towards limited breaking changes to address this issue, this inspection helps future-proof your code and minimize potential confusion. It reports variables and parameters named _ that are actually being used, making them appear as a 'discarded' value.

If a parameter or a variable name consists of multiple _ characters and has usages, it will also be reported.