Virtual methods in C#.Net

Here we will discuss about Virtual methods in C#.Net.

New to Office 365 SharePoint Online? Get Office 365 Enterprise E3 Subscription & Try out all the features

If you are declaring a method to be virtual means you are allowing the methods to be overridden in any derived classes.

The syntax is same, only we need to add the virtual keyword in method signature like below:

class MyBaseClass
public virtual string MyVirtualMethod()
return “This is the base class virtual method”;

Then in the derived class we have to use the override keyword to override the virtual method of the base class like below:

class MyDerivedClass: MyBaseClass
public override string MyVirtualMethod()
return “This is the override method of the parent class.”;

Remember Neither member fields nor static functions can be declared as virtual.

Also, check out some articles on

Get all user-defined tables in SQL Server 2008

Method Overloading in C#.Net

OOPs, concept in C#.Net.

Check out Best Alternative to InfoPath -> Try Now


(Installation & Features)

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site

View all posts by Bijay Kumar →