Događaj
Izgradite inteligentne aplikacije
17. mar 21 - 21. mar 10
Pridružite se seriji sastanaka kako biste izgradili skalabilna AI rešenja zasnovana na stvarnim slučajevima korišćenja sa kolegama programerima i stručnjacima.
Registrujte se odmahOvaj pregledač više nije podržan.
Nadogradite na Microsoft Edge biste iskoristili najnovije funkcije, bezbednosne ispravke i tehničku podršku.
The compiler generates the following errors for invalid pattern match expressions:
The compiler generates the following warnings for incomplete pattern matching expressions:
The compiler generates CS9134 to help you convert a switch statement to a switch expression. The case
keyword isn't used in a switch expression. If you have the case
keyword in a switch expression, it must be removed:
var answer = x switch
{
// CS9134: remove the keyword "case" from each switch arm:
case 0 => false,
case 1 => true,
}
The compiler generates CS9135 when the pattern isn't a constant value. You can't create pattern matching expressions to match against a variable.
The following code snippets generate CS8509:
// CS8509.cs
enum EnumValues
{
Value1,
Value2,
Value3
}
void Method(EnumValues enumValues)
{
var result = enumValues switch
{
EnumValues.Value1 => 1,
EnumValues.Value2 => 2,
};
}
To address this warning, add switch arms that cover all possible input values. For example:
enum EnumValues
{
Value1,
Value2,
Value3
}
void Method(EnumValues enumValues)
{
var result = enumValues switch
{
EnumValues.Value1 => 1,
EnumValues.Value2 => 2,
EnumValues.Value3 => 3,
_ => throw new ArgumentException("Input isn't a valid enum value", nameof(enumValues)),
};
}
The _
pattern matches all remaining values. One scenario for the _
pattern is matching invalid values, as shown in the preceding example.
For more information, see Switch.
Povratne informacije za .NET
.NET je projekat otvorenog koda. Izaberite vezu da biste pružili povratne informacije:
Događaj
Izgradite inteligentne aplikacije
17. mar 21 - 21. mar 10
Pridružite se seriji sastanaka kako biste izgradili skalabilna AI rešenja zasnovana na stvarnim slučajevima korišćenja sa kolegama programerima i stručnjacima.
Registrujte se odmah