How to Resolve Warning "CS0114: 'function1' hides inherited member 'function2'" in C#
The Compiler Warning CS0114 is an ambiguity warning related to Inheritance. The message reads: " 'Child.Method' hides inherited member 'Parent.Method'. To make the current method override that implementation, add the override keyword. Otherwise add the new keyword."
In C#, when a derived class declares a member with the same name and signature as a member in its base class, the compiler needs to know your intention.
- Do you want to Override the base behavior (Polymorphism)?
- Do you want to Hide the base behavior and start a new definition (Shadowing)?
Because you didn't specify override or new, the compiler defaults to Hiding but warns you that this might not be what you intended.
Understanding Hiding vs. Overriding
override: The method participates in the virtual inheritance chain. Even if the object is cast to theBaseClass, theChildClassversion of the method runs.new: The method breaks the inheritance chain. If the object is cast toBaseClass, theBaseClassversion runs. If cast toChildClass, theChildClassversion runs.
CS0114 occurs when you simply omit the keyword, leaving the behavior ambiguous to the reader (though the compiler treats it as new).
Scenario 1: Intending to Override (Polymorphism)
This is the most common cause. You defined a virtual method in the parent and wrote a method with the same name in the child, expecting it to replace the parent's logic, but you forgot the override keyword.
Example of warning
public class Animal
{
public virtual void Speak()
{
Console.WriteLine("Generic Animal Sound");
}
}
public class Dog : Animal
{
// ⛔️ Warning CS0114: 'Dog.Speak()' hides inherited member 'Animal.Speak()'.
// Did you mean to override it?
public void Speak()
{
Console.WriteLine("Bark");
}
}
Solution: Add 'override'
If the base member is marked virtual, abstract, or override, and you want to modify its behavior, use override.
public class Dog : Animal
{
// ✅ Correct: Explicitly overrides the base method
public override void Speak()
{
Console.WriteLine("Bark");
}
}
Behavior Check:
With override, ((Animal)myDog).Speak() will output "Bark".
Scenario 2: Intending to Hide (Shadowing)
Sometimes the base class has a method that is not virtual, or you specifically want to create a method that has the same name but is semantically different and unconnected to the parent.
Example of warning
public class Logger
{
public void Log(string msg) => Console.WriteLine($"[Base] {msg}");
}
public class CustomLogger : Logger
{
// ⛔️ Warning CS0114: Hides inherited member.
// Since base.Log is NOT virtual, we cannot override it.
// We must explicitly hide it using 'new' to silence the warning.
public void Log(string msg) => Console.WriteLine($"[Custom] {msg}");
}
Solution: Add 'new'
Use the new keyword to explicitly tell the compiler (and other developers): "I know the parent has a method named Log. I am intentionally creating a separate method also named Log."
public class CustomLogger : Logger
{
// ✅ Correct: Explicitly shadows the base method
public new void Log(string msg) => Console.WriteLine($"[Custom] {msg}");
}
Behavior Check:
With new, ((Logger)myCustomLogger).Log("Hi") will output "[Base] Hi". The child logic is ignored when treated as the parent type.
Conclusion
CS0114 asks you to be explicit about your inheritance logic.
- Check the Parent: Is the parent method
virtual? - Decide the Goal:
- If you want Polymorphism (Child logic runs everywhere), add
override. - If you want Shadowing (Child logic runs only on Child type), add
new.
- If you want Polymorphism (Child logic runs everywhere), add