- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.
Example
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); Console.ReadKey(); } } }
Output
Monday: 1 Friday: 5
Advertisements