CodeToLive

Methods and Functions

Methods are reusable blocks of code that perform a specific task. They can take parameters and return values.

Defining a Method


int Add(int a, int b)
{
    return a + b;
}

int result = Add(5, 10); // Output: 15
      

Method Overloading

C# supports method overloading, where multiple methods can have the same name but different parameters.


int Add(int a, int b)
{
    return a + b;
}

double Add(double a, double b)
{
    return a + b;
}
      
Next: Classes and Objects