Filter by Tags

Get int value from enum in C#

Votes

0

0 0

If we have an enum data type in C#, how can we get the integer value corresponding to the enum value. For example consider the following enum


enum Gender


{


    Male,


    Female


}


How to find the integer value corresponding the Female option in this enum ?

Open E-School
Posted on : Sun, Jan 07, 2018
Views : 101
Comments

Ask Question

If you want to ask question you must LogIn or SignUp
Login SignUp

Answers (1)


0

In C# we can typecast the enum data member into integer to get its corresponding integer value. For example, in the Gender enum mentioned in the question if we wish to get the integer value corresponding to the Female member of the enum, we can do so by writing the following code

int value = (int)Gender.Female;

For more details please go through the following article

http://openeschool.com/tutorial/3180/how-to-get-int-value-from-enum-in-csharp

Ravinder Singh
Thu, Jan 18, 2018
Loading...
Comments

Edit Answer

Submit
This answer will permanently deleted. Do you really want to delete this Answer ?
To Add your Answer Please
LogIn | SignUp

Quick Links

E-Magazines

@

Total Followers
Study Group Created
Study Group Joined
Following Teacher
Following Organization
Blog Articles Added
Questions Asked
Questions Answered
Jobs Posted
Total Members in Group
Questions asked by members
Tasks added in this Group

Please wait..

Ok

Login to Open ESchool OR Create your account    Login   SignUp