Note: Every case statement must end with a 'break;', signifying the end of that case's code.
Here is a simple example using a Switch-Case statement.
With ints:
int test = 3;
switch(test)
{
   case 1:
      Console.WriteLine("1");
      break;
   case 2:
      Console.WriteLine("2");
      break;
   case 3:
      Console.WriteLine("3");
      break;
   default:
      Console.WriteLine("Int is not 1-3");
      break;
}
Output: 2With Strings:
string test = "Weeee!";
switch(test)
{
   case "Wee.":
      Console.WriteLine("Meh.");
      break;
   case "Weee.":
      Console.WriteLine("Eh.");
      break;
   case "Weeee!":
      Console.WriteLine("Now You're Excited!");
      break;
   default:
      Console.WriteLine("Do Something");
      break;
}
Output: Now You're Excited!

 
 
 
 Posts
Posts
 
 
0 comments:
Post a Comment