xxxxxxxxxx
string WaterState(int tempInFahrenheit) =>
tempInFahrenheit switch
{
(> 32) and (< 212) => "liquid",
< 32 => "solid",
> 212 => "gas",
32 => "solid/liquid transition",
212 => "liquid / gas transition",
};
xxxxxxxxxx
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