ReSharper 2024.1 Help

Code Inspection: Local variable hides member

Category

Potential Code Quality Issues

ID

LocalVariableHidesMember

EditorConfig

resharper_local_variable_hides_member_highlighting

Default severity

Warning

Language

C#, VB.NET

Requires SWA

No

Having a local variable with the same name as a field effectively hides a member field. Here is an example:

class Person { string name; void DoSomething() { string name = "..."; } }

This can lead to a confusing situation as someone might assume that the name they are referring to in the DoSomething() method is the field previously defined.

Last modified: 15 April 2024