Answers for "switch expression bools"

0

switch expression bools

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
Posted by: Guest on September-08-2021

Code answers related to "switch expression bools"

Code answers related to "Javascript"

Browse Popular Code Answers by Language