To override a property on a subclass in C#, you need to use the override
keyword. Here's an example:
main.cs216 chars10 lines
In this example, ChildClass
inherits from ParentClass
and overrides the MyProperty
property with its own implementation. The override
keyword specifies that the new implementation should be used instead of the one defined in the base class.
You can then use the MyProperty
property on an instance of the ChildClass
to access its value:
main.cs106 chars3 lines
If you create an instance of the ChildClass
and access its MyProperty
property, you will get "Child Property" instead of "Parent Property".
gistlibby LogSnag