How to Resolve Warning "CS0109: The member 'member' does not hide an accessible member" in C#
The Compiler Warning CS0109 is a code cleanup warning. The message reads: "The member 'Child.Method' does not hide an accessible member. The new keyword is not required."
In C#, the new modifier is used explicitly to hide a member inherited from a base class (shadowing). This warning occurs when you apply the new keyword to a method, property, or field, but the compiler cannot find any member in the base class with the same name to hide. Essentially, the compiler is saying: "You are trying to solve a naming conflict that doesn't exist."
This guide explains why this redundancy happens and how to keep your code clean.
Understanding the 'new' Modifier
The new keyword is designed for this specific scenario:
- Parent has
public void DoWork(). - Child wants its own
public void DoWork(), unrelated to the parent's version. - You add
newto the Child's method to suppress the collision warning (CS0108).
If the Parent does not have DoWork(), adding new to the Child serves no purpose.
Scenario 1: Refactoring Leftovers (The Most Common Cause)
This usually happens after code refactoring. Perhaps the base class used to have a method with that name, but it was deleted or renamed. The derived class still has the new keyword, which is now obsolete.
Example of error
public class BaseClass
{
// Formerly: public void Compute() { ... }
// This method was removed or renamed, so the base is now empty.
}
public class DerivedClass : BaseClass
{
// ⛔️ Warning CS0109: The member 'Compute' does not hide an accessible member.
// The new keyword is not required.
public new void Compute()
{
System.Console.WriteLine("Computing...");
}
}
Solution: Remove the Keyword
Simply delete the new modifier. It changes nothing about how the code executes.
public class DerivedClass : BaseClass
{
// ✅ Correct: No base member to hide, so just declare it normally.
public void Compute()
{
System.Console.WriteLine("Computing...");
}
}
Scenario 2: Hiding Private Members
Member hiding only applies to accessible members (public, protected, or internal). If the base class has a private method, that method is invisible to the child class. Since the child class cannot see it, it cannot "hide" it.
Example of error
public class Parent
{
// Private members are not inherited in a visible way.
private void Secret() { }
}
public class Child : Parent
{
// ⛔️ Warning CS0109: You cannot hide something you cannot see.
// To the compiler, 'Secret' in Child is a brand new method
// that has no relation to 'Secret' in Parent.
public new void Secret() { }
}
Solution
Remove the new keyword. The two methods are already distinct because the parent's version is strictly private.
public class Child : Parent
{
// ✅ Correct: This is implicitly a new method.
public void Secret() { }
}
If you change the Parent method from private to protected or public later, the new keyword (or renaming) would then become necessary to avoid a collision.
Conclusion
CS0109 is a housekeeping message.
- Check the Base Class: Does the member you are trying to hide actually exist in the parent?
- Check Accessibility: Is the parent member
private? If so, you don't neednew. - The Fix: Simply delete the
newkeyword. Your code will behave exactly the same, but the warning will disappear.