C#: Enums Cheat Sheet

enum <enum_name> {
   enumeration list 
};
  • The enum_name specifies the enumeration type name.
  • The enumeration list is a comma-separated list of identifiers.

Example

using System;

namespace EnumApplication {
   class EnumProgram {
      enum Colors { Red, Pink, Blue, Black, White, Purple };

      static void Main(string[] args) {
         int FistColor = (int)Colors.Red;
         int LastColor = (int)Days.Purple;
         
         Console.WriteLine("Red: {0}", FistColor);
         Console.WriteLine("Purple: {0}", LastColor);
         Console.ReadKey();
      }
   }
}

=> output

Red: 0
Purple: 5

Leave a Reply

Your email address will not be published. Required fields are marked *