विभिन्न तरीकों से एक विधि को ओवरलोड किया जा सकता है -
The datatypes of parameters are different The number of parameters are different
निम्नलिखित पैरामीटर के विभिन्न डेटाटाइप बताते हुए एक उदाहरण देता है -
void print(int i) {
Console.WriteLine("Printing int: {0}", i );
}
void print(double f) {
Console.WriteLine("Printing float: {0}" , f);
}
void print(string s) {
Console.WriteLine("Printing string: {0}", s);
} निम्नलिखित मापदंडों की अलग-अलग संख्या बताता है -
// two parameters
public static int mulDisplay(int one, int two) {
return one * two;
}
// three parameters
public static int mulDisplay(int one, int two, int three) {
return one * two * three;
}
// four parameters
public static int mulDisplay(int one, int two, int three, int four) {
return one * two * three * four;
}