Enums in Csharp Programming Language

What is Enums in C#?

enum (C# Reference) The enum keyword is used to declare an enumeration, a distinct type that consists of a set of named constants called the enumerator list. Enums in Csharp are Value data types.The enumerated type is declared using a keyword enum.

The syntax of enum

enum_name – Name of the enumeration
enumeration list constants – List of enum constants. This will be comma-separated identifiers.

Example of enum in C#

How to enumerate enum in C#

The below example enumerates all the names or the constants that have been provided in the enum list.

The below example enumerates all the Integer values of the enum MachineState

How to cast int to enum in C# and string to enum in C#

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.