How do we use enum keyword to define a variable type in C#?

C# enumerations are value data type. An enumeration is a set of named integer constants. An enumerated type is declared using the enum keyword.

The following is the syntax of enum.

enum <enum_name> {
   enumeration list

Let us see an example.

enum Vehicle { Car, Bus, Truck };

The following is an example showing how to use enum keyword to define variable type.


 Live Demo

using System;
namespace Demo {
   class Program {
      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);


Monday: 1
Friday: 5
karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know