Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Vivek KumarRank #272 · 9.3K reputationPosted Jun 27, 2017, 11:08 PM EDT
Naveen ArumugamRank #1,227 · 1.5K reputationPosted Jun 27, 2017, 11:10 PM EDT
Anil JhaRank #1,988 · 733 reputationPosted Jun 27, 2017, 11:39 PM EDT
Vivek KumarRank #272 · 9.3K reputationPosted Jun 27, 2017, 11:34 PM EDT
Brajesh KumarRank #678 · 3.5K reputationPosted Jun 27, 2017, 11:51 PM EDT
An enumeration is a set of named integer constants. An enumerated type is declared using the enum keyword.
C# enumerations are value data type. In other words, enumeration contains its own values and cannot inherit or cannot pass inheritance.
Declaring enum Variable
The general syntax for declaring an enumeration is:
Where,
The enum_name specifies the enumeration type name.
The enumeration list is a comma-separated list of identifiers.
Each of the symbols in the enumeration list stands for an integer value, one greater than the symbol that precedes it. By default, the value of the first enumeration symbol is 0. For example:
Example
The following example demonstrates use of enum variable:
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 result:
Rajkiran SwainRank #165 · 14.4K reputationPosted Jun 28, 2017, 12:43 AM EDT
Guest UserRank #4,500 · 340 reputationPosted Jun 28, 2017, 1:20 AM EDT