Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

c# switch

public enum Color { Red, Green, Blue, Black, Orange }
public static void RandomConsoleBackground()
{
   Color c = (Color)(new Random()).Next(0, 4);
   switch (c)
   {
   case Color.Red:
      Console.BackgroundColor = ConsoleColor.Red;
      Console.Clear();
      Console.WriteLine("Red");
   break;
   case Color.Green:
      Console.BackgroundColor = ConsoleColor.Green;
      Console.Clear();
      Console.WriteLine("Green");
   break;
   case Color.Blue:
   case Color.Black:
   case Color.Orange:
   default:
      Console.WriteLine("No need to change background.");
   break;
}
Source by www.c-sharpcorner.com #
 
PREVIOUS NEXT
Tagged: #switch
ADD COMMENT
Topic
Name
8+1 =