C# Overloading methods

If you’re new to C#, this is a very important concept. In some languages such as Ruby, this concept doesn’t exist.

Overloading methods is the idea that you can have two methods with the same name, but different signatures.

Signatures refers to the name of the methods and it’s parameter type or types.


public static void print() {
Console.WriteLine("There are no parameters to print");
public static void print(string name) {
Console.WriteLine("Printing {0}", name);

As you can see above we have two methods with the name print() . Both of them have different signatures. The first print() method doesn’t contain any parameters, while the second print() method contains the parameter name with the type of string .

In your application, you can call either method without raising an error.

If I called the same method with the same parameter type or in this case nothing at all since there is a print() method without any parameters, it will throw an error.

public static void say_hello(string name)
Console.WriteLine("Hello {0}", name);
public static void say_hello(string phrase)

So this is illegal because you cannot have two methods of the same name with the same type for parameter if they both contain the same amount of parameters.