Get to know C# Enums - CSharp Custom Type

CSharp examples for Custom Type:Enum

Introduction

An enumeration is a set of named integer constants.

C# enumerations contains its own values and cannot inherit or cannot pass inheritance.

The general syntax for declaring an enumeration is ?

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

Demo Code

using System;/*from  www . j  a  v a  2  s .  c o  m*/
class EnumProgram {
   enum Days { Sun, Mon, tue, Wed, thu, Fri, Sat };
   static void Main(string[] args) {
      int WeekdayStart = (int)Days.Mon;
      int WeekdayEnd = (int)Days.Fri;
      Console.WriteLine("Monday: {0}", WeekdayStart);
      Console.WriteLine("Friday: {0}", WeekdayEnd);
   }
}

Result


Related Tutorials