方法在 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