方法在 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;
}
// 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;
}
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP