Virtual
Applies to methods, properties, events, indexers
Virtual Methods
A virtual method indicates that a member can be redefined in a derived class
You canot use this modifier in conjunction with static, abstract, override
All virtual methods must be declared as public
Any derived classes then have the option to override this if necessary
It is often used when more functionality is required in the derived class
class Base
{
public virtual void Test()
{
}
}
class Derived : Base
{
public override void Test()
{
}
}
When a derived class overrides a virtual method the base class method is not called
It is possible to explicitly run the base class method by using
base.VirtualMethod()
Virtual Properties
© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext