【发布时间】:2019-09-27 19:15:43
【问题描述】:
在 C# 8 中,引入了 switch 表达式。如果 switch 表达式不详尽会发生什么?换句话说,如果我不测试每个可能的值会发生什么?
static void Main(string[] args)
{
int x = 1;
int imExhaustive = x switch
{
3 => 4,
_ => 0 // x = 1 matches this
};
int okFine = x switch
{
1 => 4 // x = 1 matches this
};
int noMatch = x switch
{
3 => 4 // No match
};
}
【问题讨论】:
标签: c# c#-8.0 switch-expression