C# (C Sharp) - Method Overloading | Method Overriding

C# (C Sharp) - Method Overloading

Method Overloading Method Overloading is the common way of implementing polymorphism. It is the ability to redefine a function in more than one form. A user can implement function overloading by defining two or more functions in a class sharing the same name. C# can distinguish the methods with different method signatures. i.e. the methods can have the same name but with different parameters list (i.e. the number of the parameters, order of the parameters, and data types of the parameters) within the same class. 

// C# program to demonstrate the function overloading by changing the Number of parameters 

using System; 

class GFG 

// adding two integer values. 

public int Add(int a, int b) 

int sum = a + b; 

return sum;

// adding three integer values. 

public int Add(int a, int b, int c) 

int sum = a + b + c; 

return sum;

// Main Method 

public static void Main(String[] args) 

// Creating Object 

GFG ob = new GFG(); 

int sum1 = ob.Add(1, 2); 

Console.WriteLine("sum of the two "+" integer value : " + sum1); 

int sum2 = ob.Add(1, 2, 3); 

Console.WriteLine("sum of the three “+" integer value : " + sum2); 

C# (C Sharp) - Method Overriding

Method Overriding in C# is similar to the virtual function in C++. Method Overriding is a technique that allows the invoking of functions from another class (base class) in the derived class. Creating a method in the derived class with the same signature as a method in the base class is called as method overriding. 


class base 

public void gfg(); 

class derived : base 

public void gfg(); 

class Main_Method 

static void Main() 

derived d = new derived(); 


Here the base class is inherited in the derived class and the method gfg() which has the same signature in both the classes, is overridden. 

"method overloading in c#"

"method overriding in c#"

"method overriding in c# with example"

"overloading and overriding in c#"

"c sharp method overloading"

"c sharp override method"

"c sharp overload"

"method overloading in c sharp with example"

"c sharp override"

"c# method overloading and overriding"