Switch Expression Bools

[Solved] Switch Expression Bools | Matlab - Code Explorer | yomemimo.com
Question : switch expression bools

Answered by : antti-veikkolainen

string startsWith = "somestring:";
// Note: this works with any data type 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

Source : | Last Update : Wed, 15 Sep 21

Answers related to switch expression bools

Code Explorer Popular Question For Matlab