← Back to C# Course | Chapter 5: Methods | Lesson 4 of 6

Method Overloading

In this page:

  1. Method Overloading

Method Overloading

Overloading lets several methods share the same name as long as their parameter lists differ in type or count. The compiler picks the right overload based on the arguments at the call site. Overloading is resolved entirely at compile time, not based on runtime values.

Note: Overloads should behave consistently — same name, conceptually the same operation, just different inputs.

Example: Method Overloading

markup
using System;

class Program
{
    static int Add(int a, int b) => a + b;
    static double Add(double a, double b) => a + b;
    static int Add(int a, int b, int c) => a + b + c;

    static void Main(string[] args)
    {
        Console.WriteLine(Add(2, 3));
        Console.WriteLine(Add(2.5, 3.5));
        Console.WriteLine(Add(1, 2, 3));
    }
}
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.