Saturday, 18 August 2018

C#: Method Overloading

Methods within a class can have the same name with different signature. In C#, methods are overloaded by using
         a. Number of parameters
         b. Type of parameters
         c. Kind of parameters (value, ref (or) out)
        
Program.cs
class Arithmetic
{
    public int sum(int a, int b)
    {
        return a + b;
    }

    public float sum(int a, float b)
    {
        return a + b;
    }

    public void sum(int a, out int b)
    {
        b = a + a;
    }

    public int sum(ref int a, ref int b)
    {
        return a + b;
    }
}



Previous                                                 Next                                                 Home

No comments:

Post a Comment