Method Overloading and Method overriding C#.Net

In this post, we will discuss what is the difference between method overloading and overriding in C#.Net.

Method Overloading:

Method Overloading means more than one method having the same name but different Signatures that is number and type of parameter.

Example:
public class MyClass
{
public int AddNumbers(int firstnumber, int secondnumber)
{
return firstnumber + secondnumber;
}

public int AddNumbers(int firstnumberr, int secondnumber,int thirdnumber)
{
return firstnumber + secondnumber + thirdnumber;
}
}

Method Overriding:

Method overriding comes in base class and derived class. If two methods with same name and same signature, and one method is in the base class and another method will in derived class then it will be known as method overriding. This will be possible by using virtual and override keywords.

We have to use Virtual keyword for the method in the base class and override keyword will be written in the derived class.

public class MyBaseClass
{
public virtual int AddNumbers(int firstnumber, int secondnumber)
{
return firstnumber + secondnumber;
}
}

public class MyChildClass:MyBaseClass
{
public int AddNumbers(int firstnumber)
{
return firstnumber + secondnumber + 100;
}
}


Here method name and signature should be same. And it will need inheritance.

Hope this will be helpful.


You May Also like the Following SharePoint Online Tutorials:

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 SharePointSky.com

View all posts by Bijay Kumar →

Leave a Reply