Answers for "which case multi condition c#"

C#
4

can you have multiple statement in a case c#

switch (value)
{
    case 1: case 2: case 3:          
        // Do Something
        break;
    case 4: case 5: case 6: 
        // Do Something
        break;
    default:
        // Do Something
        break;
}
Posted by: Guest on August-20-2020
0

multi case in c#

switch (value)
{
   case var s when new[] { 1,2,3 }.Contains(s):
      // Do something
      break;
   case var s when new[] { 4,5,6 }.Contains(s):
      // Do something
      break;
   default:
      // Do the default
      break;
}
Posted by: Guest on October-30-2020

C# Answers by Framework

Browse Popular Code Answers by Language