Online Training for MVC Web Designing Development, MS SQL, Digital Marketing

Learn Enums in C# Tutorial

In this article we learn about enum in C#

What is enum in C# .Net

Enum is a value type in .net data type, Enum is an abstract class that has some static methods to work with enum. Before we see some enum example, let's take a look at the methods of System.Enum.

Method Description
GetName Gets the name of the constant in the specified enumeration
GetNames Returns a string array of constant names
GetValues Returns an array of constant values

C# Enum Example

enum EventState
Initiated = 1,
Started = 2,
Closed = 3,
Canceled = 4

Enum GetNames Example
foreach (string str in Enum.GetNames(typeof(EventState)))

Enum GetValues Example
foreach (int i in Enum.GetValues(typeof(EventState)))

//this will print the number 2

// this will print string "Started"

You may also check How to convert enum to generic list type

Name Email Website
Enums in C#
in C# Tutorials
Learn C# Online Tutorial

Group Training