CA1500: Variable names should not match field names
TypeName | VariableNamesShouldNotMatchFieldNames |
CheckId | CA1500 |
Category | Microsoft.Maintainability |
Breaking Change | When fired on a parameter that has the same name as a field:
When fired on a local variable that has the same name as a field:
|
When the name of an instance field matches a parameter or a local variable name, the instance field is accessed by using the this (Me in Visual Basic) keyword when inside the method body. When maintaining code, it is easy to forget this difference and assume that the parameter/local variable refers to the instance field, which leads to errors. This is true especially for lengthy method bodies.