I have this Base class:
abstract class Base
{
public int x
{
get { throw new NotImplementedException(); }
}
}
And the following descendant:
class Derived : Base
{
public int x
{
get { //Actual Implementaion }
}
}
When I compile I get this warning saying Derived class’s definition of x is gonna hide Base’s version of it. Is is possible to override properties in c# like methods?
You need to use
virtualkeywordor define an abstract property:
and use
overridekeyword when in the child:If you’re NOT going to override, you can use
newkeyword on the method to hide the parent’s definition.