在C#中重载方法有哪些不同的方式?
重载方法的不同方式是-
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;
}
//三个参数
public static int mulDisplay(int one, int two, int three) {
return one * two * three;
}
//四个参数
public static int mulDisplay(int one, int two, int three, int four) {
return one * two * three * four;
}热门推荐
10 给女儿祝福语简短精辟
11 对上司的简短祝福语
12 关云生字祝福语简短
13 送给情侣贺卡祝福语简短
14 孙媳妇祝福语简短
15 兄弟的结婚祝福语简短
16 毕业祝福语简短英语小学
17 弟弟的祝福语简短霸气
18 朋友搬迁新房祝福语简短