

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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
- Related Questions & Answers
- How do we use an enum type with a constructor in Java?
- How to define an enumerated type (enum) in C++?
- How do we use function literal to define a function in JavaScript?
- Why do we use internal keyword in C#?
- How to convert an enum type variable to a string in C++?
- Why do we use the params keyword in C#?
- Can we define an enum inside a class in Java?
- Can we define an enum inside a method in Java?
- How do we define tuple in Python?
- How do we define lists in Python?
- How do we define dictionary in Python?
- How do we define a dialog box in HTML?
- How do we initialize a variable in C++?
- What is MySQL ENUM data type? What are the advantages to use ENUM data type?
- How to define a variable in C++?
Advertisements