How can we loop through ENUM values

We can use “GetValues()” method of the “ENUM” class which returns an array of enum values.

var x = Enum.GetValues(typeof(MyColors));

What is the use of “ENUM.Parse” method?

“ENUM.Parse” parses string to an ENUM value. Like in the below code we pass “Green” string value and it gets type casted to enum which has green enum as a constant.

MyColors EnumColors = (MyColors)Enum.Parse(typeof(MyColors), “Green”);

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s