ホームページ >バックエンド開発 >C#.Net チュートリアル >C# でメソッドをオーバーロードするさまざまな方法には何がありますか?

C# でメソッドをオーバーロードするさまざまな方法には何がありますか?

王林
王林転載
2023-09-10 15:13:05718ブラウズ

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;
}

以上がC# でメソッドをオーバーロードするさまざまな方法には何がありますか?の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事はtutorialspoint.comで複製されています。侵害がある場合は、admin@php.cn までご連絡ください。