Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

What is Virtual Method in C#?

user-image
Question added by Mohannad Bakbouk , Full Stack Web Developer , Almohtaseb
Date Posted: 2016/10/20
Hassan Elsherbiny
by Hassan Elsherbiny , .Net Developer , Al-dar international

when you create a method as virtual you can use it as it is in the sub classes(classes inherits from the original class containing the method)or Override it to define another behavior for this method for this class only (the child class)

Mohannad Bakbouk
by Mohannad Bakbouk , Full Stack Web Developer , Almohtaseb

A virtual method is a method that can be redefined in derived classes. A virtual method has an implementation in a base class as well as derived the class. It is used when a method's basic functionality is the same but sometimes more functionality is needed in the derived class. A virtual method is created in the base class that can be overridden in the derived class. We create a virtual method in the base class using the virtual keyword and that method is overridden in the derived class using the override keyword.

More Questions Like This