Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어
マニュアルC# · 例題UO
テンプレートは同時に値をチェックし、データを取得できます。定数、型、プロパティ、位置、関係、リスト、および論理組み合わせ and、or、not のテンプレートが利用可能です。 _は破棄された値を示します。
and
or
not
_
この例を Example.cs として別に保存し、このページの他の例とは独立して実行してください。
Example.cs
Example.cs:
// PROJECT-EXAMPLE int value = 15; System.Console.WriteLine(value is > 10 and < 20);
結果:
True
object value = "backpack"; if (value is string { Length: > 0 } name) { UO.Print(name); }
int[] numbers = [1, 2, 3]; string shape = numbers switch { [1, .., 3] => "starts with 1 and ends with 3", [] => "empty", _ => "other" }; UO.Print(shape);
公式ドキュメント: パターン マッチング - Microsoft Learn。
There was an error while loading. Please reload this page.