Code2night
  • Home
  • Guest Posts
  • Tutorial
  • Languages
    • Angular
    • C
    • C#
    • HTML/CSS
    • Java
    • JavaScript
    • Node.js
    • Python
    • React
    • SQL Server
    • TypeScript
  • Post Blog
  • Tools
    • JSON Beautifier
    • HTML Beautifier
    • XML Beautifier
    • CSS Beautifier
    • JS Beautifier
    • PDF Editor
    • Word Counter
    • Base64 Encode/Decode
    • Diff Checker
    • JSON to CSV
    • Password Generator
  • Register
  • Login
  1. Home
  2. Blogpost

Method Overloading

Date- Dec 09,2023

2675

Method Overloading

In Method Overloading we have two or more than two methods those have the same name but different parameters.

Method overloading done by three ways.

  • The number of parameters change in methods.
  • The data types of the parameters change in methods
  • The order of parameters change in methods

Number of parameters

In this method overloading, the number of parameters is different in the methods.e.g one method has single parameter and another methods has more than two parameters.


 
 using System;
  public class MyCode {
   public static int AddDisplay(int one, int two) {
      return one + two;
   }

   public static int AddDisplay(int one, int two, int three) {
      return one + two + three;
   }

   public static int AddDisplay(int one, int two, int three, int four) {
      return one + two + three + four;
   }
}

public class Program {
   public static void Main() {
      Console.WriteLine("Addition of two numbers: "+MyCode.AddDisplay(10, 10));
      Console.WriteLine("Addition  of three numbers: "+MyCode.AddDisplay(5, 10, 20));
      Console.WriteLine("Addition  of four numbers: "+MyCode.AddDisplay(2, 5, 10, 20));
   }
}

 

  OUTPUT
  
Addition of two numbers: 20
Addition  of three numbers: 35
Addition  of four numbers: 37

 

Data types of the parameters

In this method overloading,the data types of parameters is different in the methods.e.g here we have different data types of parameters for same name methods that is use for overloading.


  
  using System;
  public class MyCode {
   public static int AddDisplay(int one, int two) {
      return one + two;
   }

   public static double AddDisplay(double  one, double  two, double  three) {
      return one + two + three;
   }

   public static float AddDisplay(float one, float two, float three, float four) {
      return one + two + three + four;
   }
}

public class Program {
   public static void Main() {
      Console.WriteLine("Addition of two numbers: "+MyCode.AddDisplay(10, 10));
      Console.WriteLine("Addition  of three numbers: "+MyCode.AddDisplay(5.5D, 10D, 20D));
      Console.WriteLine("Addition  of four numbers: "+MyCode.AddDisplay(2.5F, 5.5F, 10F, 20F));
   }
}
 
 

 OUTPUT
  
Addition of two numbers: 20
Addition  of three numbers: 35.5
Addition  of four numbers: 38

 

Order of parameters

In this method overloading,the order of data types of parameters is different in same name of methods.for e.g here we can change the order of data types of parameters (i.e int,string) in same name methods (i.e DisplayData)


 
 using System;
  public class MyCode {
   public void DisplayData(int a, string b) {
       Console.WriteLine("Id: " + a);
      Console.WriteLine("Name: " + b);
   }

   public void DisplayData(string b, int a) {
        Console.WriteLine("Name: " + b);
      Console.WriteLine("Id: " + a);
   }

   
}

public class Program {
   public static void Main() {
       MyCode m1 = new MyCode();
      m1.DisplayData(1, "Roy");
      m1.DisplayData("Alexa", 2);
      Console.ReadLine();
   }
}
 

OUTPUT
  
Id: 1
Name: Roy
Name: Alexa
Id: 2

S
Shubham Saini
Programming author at Code2Night โ€” sharing tutorials on ASP.NET, C#, and more.
View all posts โ†’

Comments

Tags

AspNet
C#
programming
AspNet MVC
c programming
AspNet Core
C
software development
tutorial
MVC
memory management
Paypal
coding
coding best practices
data structures
programming tutorial
tutorials
object oriented programming
Slick Slider
StripeNet
Free Download for Youtube Subscribers!

First click on Subscribe Now and then subscribe the channel and come back here.
Then Click on "Verify and Download" button for download link

Subscribe Now | 1760
Download
Support Us....!

Please Subscribe to support us

Thank you for Downloading....!

Please Subscribe to support us

Continue with Downloading
Be a Member
Join Us On Whatsapp Join Us On Facebook
Code2Night

A community platform for sharing programming knowledge, tutorials, and blogs. Learn, write, and grow with developers worldwide.

Panipat, Haryana, India
info@code2night.com
Quick Links
  • Home
  • Blogs
  • Tutorials
  • About Us
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Guest Posts
Free Dev Tools
  • JSON Beautifier
  • HTML Beautifier
  • CSS Beautifier
  • JS Beautifier
  • Password Generator
  • QR Code Generator
  • Hash Generator
  • Diff Checker
  • Base64 Encode/Decode
  • Word Counter
By Language
  • Angular
  • C
  • C#
  • HTML/CSS
  • Java
  • JavaScript
  • Node.js
  • Python
  • React
  • SQL Server
  • TypeScript
© 2026 Code2Night. All Rights Reserved.
Made with for developers  |  Privacy  ยท  Terms
Translate Page