📜  c# switch 表达式模式匹配 - C# 代码示例

📅  最后修改于: 2022-03-11 14:48:39.459000             🧑  作者: Mango

代码示例1
string startsWith = "somestring:";

 switch (startsWith)
 {
     // Using the 'when' keyword you can convert your case to a bool like
     // expression like so:
     case string when startsWith.StartsWith("somestring:"):
         Console.WriteLine("hit");
         break;

   case string when startsWith.StartsWith("someotherstring:"):
        Console.WriteLine("hit 1");
        break; 
}

// Output: hit