Enumerations
Posted by Gizmosis350k
Last Updated: April 21, 2012
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ch05Ex02
{
   enum orientation : byte
   {
      north = 1,
      south = 2,
      east = 3,
      west = 4
   }

   class Program
   {
      static void Main(string[] args)
      {
         byte directionByte;
         string directionString;
         orientation myDirection = orientation.north;
         Console.WriteLine("myDirection = {0}", myDirection);
         directionByte = (byte)myDirection;
         directionString = Convert.ToString(myDirection);
         Console.WriteLine("byte equivalent = {0}", directionByte);
         Console.WriteLine("string equivalent = {0}", directionString);

         Console.ReadKey();
      }
   }
}


This code is supposed to show the usefulness of enumerations.
Basically, from what i understand, these are variables that can map values to integers, starting with 0, or whichever integer you want assigned to them. That way, a enumeration can have a "short" and a "string" representation of the same value, or something to that effect, i will be rereading through this section in the enar future.
Related Content