Advertisement
Qrist

Random Enum

Oct 2nd, 2020
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.60 KB | None | 0 0
  1. using System;
  2.  
  3. public enum Color { Red, Green, Blue }
  4.  
  5. public class Example
  6. {
  7.    public static void Main()
  8.    {
  9.       Color c = (Color) (new Random()).Next(0, 3);
  10.       switch (c)
  11.       {
  12.          case Color.Red:
  13.             Console.WriteLine("The color is red");
  14.             break;
  15.          case Color.Green:
  16.             Console.WriteLine("The color is green");
  17.             break;
  18.          case Color.Blue:
  19.             Console.WriteLine("The color is blue");
  20.             break;
  21.          default:
  22.             Console.WriteLine("The color is unknown.");
  23.             break;
  24.       }
  25.    }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement