in C#
all methods by default are non-virtual. You can't override non-virtual method in sub-classes. So leaving property as usual will safe you from subclass overriding it.
Sealed
is a keyword used in class declaration for inheritance restrictions or is used to stop virtual chain of members of a class hierarchy. But again - this relates to virtual methods and properties.
Trying to override "normal" property in sub-class will result in compile error
'WarningIntField.DataType.get': cannot override inherited member 'BaseWarningIntField.DataType.get' because it is not marked virtual, abstract, or override
To answer you comment, I'll present some code examples to illustrate my point. You can't actually restrict derived classes from hiding a method or property. So next situation is legal and there is no way to overcome it (this related to virtual method and methods denoted with new
keyword as well)
class BaseClass
{
public string Property {get; set;}
}
class DerivedClass : BaseClass
{
//compiler will give you a hint here, that you are hiding a base class prop
public string Property {get; set;}
}
The same way you can't restrict of hiding a field in a class by local variable, so this situation is also valid. Note that compiler will also help you to note, that you are hiding class field in by a local variable. This also related to readonly
const
and simple static
fields as well.
int field = 0; //class field
void Foo()
{
int field = 0; //local variable
}