In C# can a constant be overridden in a derived class? I have a group of classes that are all the same bar some constant values, so I\'d like to create a base class that def
Edit: This can have unexpected behaviour, see Shai Petel's remark below.
You can hide the inherited constant in a derived class by declaring the new constant new
. I'm not sure this is a good practice, though.
class A
{
protected const int MyConst = 1;
}
class B : A
{
new private const int MyConst = 2;
}