ReSharper 2024.1 Help

Code Inspection: Member hides static member from outer class

Category

Potential Code Quality Issues

ID

MemberHidesStaticFromOuterClass

EditorConfig

resharper_member_hides_static_from_outer_class_highlighting

Default severity

Warning

Language

C#

Requires SWA

No

There is not much wrong with the code example below, at least in its current state where you can observe all declarations at once. However, as the FooNested class would grow and DoSomething() would be not so close to the both declarations of the Bar, someone who reads the code could mistakenly think that DoSomething() uses Foo.Bar and not FooNested.Bar. Furthermore, if someone removes the Foo declaration from FooNested later, they may not notice that the remaining usages of Foo will be returning the value of the Foo.Bar.

Therefore, ReSharper issues a warning to draw your attention to potential problems with this code. There are no quick-fixes because this declaration of the Bar is indeed intended. But if it's not and if you want to safely rename it, press F2 on it to invoke the Rename refactoring.

public class Foo { private static string Bar { get; set; } // some other members private class FooNested { private static string Bar { get; set; } static void DoSomething() { Console.WriteLine(Bar); } } }
Last modified: 15 April 2024