Advertisement
Cookie042

enums & switch

Aug 9th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.87 KB | None | 0 0
  1. using System;
  2.  
  3.  namespace ConsoleApp1
  4.  {
  5.      class Program
  6.      {
  7.          
  8.          public enum Direction
  9.          {
  10.              LEFT, RIGHT, FORWARD, BACKWARD
  11.          }
  12.          
  13.          static void Main(string[] args)
  14.          {
  15.  
  16.              Direction dir = Direction.LEFT;
  17.  
  18.              switch (dir)
  19.              {
  20.                  case Direction.LEFT:
  21.                      // go left
  22.                      break;
  23.                  case Direction.RIGHT:
  24.                      //go right
  25.                      break;
  26.                  case Direction.FORWARD:
  27.                      //go forward
  28.                      break;
  29.                  case Direction.BACKWARD:
  30.                      //go backwards
  31.                      break;
  32.                  default:
  33.                      throw new ArgumentOutOfRangeException();
  34.              }
  35.  
  36.          }
  37.      }
  38.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement