Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
what is enum data type.. why we have need to use enum , please explain .. Thnx in advance
Posted

The enum keyword is used to declare an enumeration, a distinct type that consists of a set of named constants called the enumerator list.

C#
public class EnumTest
{
    enum Days { Sun, Mon, Tue, Wed, Thu, Fri, Sat };

    static void Main()
    {
        int x = (int)Days.Sun;
        int y = (int)Days.Fri;
        Console.WriteLine("Sun = {0}", x);
        Console.WriteLine("Fri = {0}", y);
    }
}

In the above example, enums can represent and use days directly.
As a result, there is no need to define days in a collection.

Source - enum (C# Reference)[^].
 
Share this answer
 
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900