Overloading provides the ability to create multiple methods or properties with the same
name, but with different parameters lists. This is a feature of polymorphism. A simple
example would be an addition function, which will add the numbers if two integer
parameters are passed to it and concatenate the strings if two strings are passed to it.
using System;
public class test
{
public int Add(int x , int y)
{
return(x + y);
}
public string Add(String x, String y )
{
return (x + y);
}
public static void Main()
{
test a = new test ();
int b;
String c;
b = a.Add(1, 2);
c = a.Add("Reshmi", " Nair");
Console.WriteLine(b);
Console.WriteLine(c);
}
}
O/P:
3
Reshmi Nair
No comments:
Post a Comment