Get value of enum member by its name?

You want to get the Enum value from the string name. So you can use the Enum.Parse method.

int number = (int)Enum.Parse(typeof(TestAppAreana.MovieList.Movies), KeyVal)

You can also try Enum.TryParse to check whether parsing is successful or not.

Movies movie;
if (Enum.TryParse(KeyVal, true, out movie))
{

}

Assuming that KeyVal is a string representing the name of a certain enum you could do this in the following way:

int value = (int)Enum.Parse(typeof(TestAppAreana.MovieList.Movies), KeyVal);

Tags:

C#

.Net

Enums