Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Enum enum claims and uses


May 11, 2021 C#


Table of contents


The enumerant (Enum).

Enumerals are a set of named integer constants. The enumerant type is declared using the enum keyword.

The C#enumeration is a value data type. In other words, enumeration contains its own values and cannot inherit or pass inheritance.

Declare the enum variable

General syntax for declaring enumerations:

enum <enum_name>
{ 
    enumeration list 
};

Among them,

  • enum_name specifies the type name of the enumeration.
  • The enumeration list is a list of identifiers separated by commas.

Each symbol in the enumeration list represents an integer value, a larger integer value than the symbol before it. By default, the value of the first enumeration symbol is 0. For example:

enum Days { Sun, Mon, tue, Wed, thu, Fri, Sat };

The following example demonstrates the use of enumeration variables:

using System;
namespace EnumApplication
{
   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);
         Console.ReadKey();
      }
   }
}

When the above code is compiled and executed, it produces the following results:

Monday: 1
Friday: 5