

- 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
Enum with Customized Value 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. However you can still change the start index and customize it with the value of your choice.
In the following example, I have set the customized value to be 20 instead of the default 0.
Example
using System; public class Demo { public enum Vehicle { Car =20, Motorcycle, Bus, Truck } public static void Main() { int a = (int)Vehicle.Car; int b = (int)Vehicle.Motorcycle; int c = (int)Vehicle.Bus; int d = (int)Vehicle.Truck; Console.WriteLine("Car = {0}", a); Console.WriteLine("Motorcycle = {0}", b); Console.WriteLine("Bus = {0}", c); Console.WriteLine("Truck = {0}", d); } }
Output
Car = 20 Motorcycle = 21 Bus = 22 Truck = 23
- Related Questions & Answers
- Enum with Customized Value in Java
- Create a DataFrame with customized index parameters in Pandas
- How to call another enum value in an enum's constructor using java?
- How to sort an array with customized Comparator in Java?
- How to get int value from enum in C#?
- Java Program to Lookup enum by String value
- Select records with ACTIVE status in MySQL set with ENUM
- Enum with NOT NULL in a MySQL field?
- How can I insert default value in MySQL ENUM data type?
- How can I remove a value from an enum in MySQL?
- Enum in Java
- Enum in C#
- Enum in C
- Enum in Python
- What MySQL returns if I insert invalid value into ENUM?
Advertisements