메소드를 오버로드할 수 있는 다양한 방법은 다음과 같습니다. -
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;
}