- Trending Categories
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
Enum in C#
Enum is Enumeration to store a set of named constants like year, product, month, season, etc.
The default value of Enum constants starts from 0 and increments. It has fixed set of constants and can be traversed easily.
Let us see an example.
We have set the enum like this −
public enum Vehicle { Car, Bus, Truck }
The following is the complete example.
Example
using System; public class Demo { public enum Vehicle { Car, Bus, Truck } public static void Main() { int a = (int)Vehicle.Car; int b = (int)Vehicle.Bus; int c = (int)Vehicle.Truck; Console.WriteLine("Car = {0}", a); Console.WriteLine("Bus = {0}", b); Console.WriteLine("Truck = {0}", c); } }
Output
Car = 0 Bus = 1 Truck = 2
Advertisements