Method Overloading
Overloading
Declaring multiple methods with the same name.
Differentiated by the number of parameters, and the type of parameters.
Useful for declaring functions that may do similar tasks but take in different parameters.
Valid Overloading
static void Add(int a, int b)
{
Console.WriteLine(a + b);
}
static int Add(int a, int b)
{
return a + b;
}Parameters are identical but return type is different.
Invalid Overloading
Number of parameters or their type (or both) difference.
Last updated