Charlie Calvert on Elvenware

Writing Code and Prose on Computers

Elvenware

Methods

Method Overloading

Though both of these methods have the same name, they can still be placed in the same class because they have different signatures. The first method's signature states that it takes two integers as parameters, while the second method's signature shows that it takes two doubles as parameters. The return values of the methods are not considered part of the signature. Hence, if the two methods each took two integers as parameters, but one returned an integer and the other a double they would not be considered valid overrides and would cause an CS0111 error at compile time: A class contains two identical member declarations.

NOTE: Be careful not to confuse method overloading, discussed here, with method overriding. The latter has to do with polymorphism and involves redefining a method declared in a base class.

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

public double Add(double a, double b)
{
    return a + b;
}