1string startsWith = "somestring:";
2
3// Note: this works with any data type
4 switch (startsWith)
5 {
6 // Using the 'when' keyword you can convert your case to a bool like
7 // expression like so:
8 case string when startsWith.StartsWith("somestring:"):
9 Console.WriteLine("hit");
10 break;
11
12 case string when startsWith.StartsWith("someotherstring:"):
13 Console.WriteLine("hit 1");
14 break;
15}
16
17// Output: hit