Enum in C# | What is Enum | Enumeration type in C# | C# Bangla Tutorial | Advanced C#

 


What is Enum?

Enums are strongly typed constants which makes the code more readable. If you have a number of constants that are logically related to each other, then you can group together these constants in an enumeration. The main advantage of Enum is make it easy to change values in the future, also you can reduces errors caused by transposing or mistyping numbers.


Syntax


It can be defined using the enum keyword.

enum<enum_name>

{

  //enumartion list

}



Creating an enumeration type


enum OrderStatus

{

  OederPlace,

  OrderConfirmed,

  Packaging,

  Delivering,

  Received

};


Important points


1. Enums are strongly typed constants.

2. Enumerations (enums) make your code more readable and understandable.

3. Enum values are fixed. enum can be displayed as a string and processed as an integer.

4. The default type is int, and the approved types are byte, sbyte, short, ushort, uint, long, and ulong.

5. Enums are not for end-users, they are meant for developers.


Post a Comment

Previous Post Next Post