Get value of enum member by its name?
.net, c#, enums
Solution
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);
Problem
Say that I have variable whose value (for example, `"listMovie"`) is the name of an `enum` member: ``` public enum Movies { regMovie = 1, listMovie = 2 // member whose value I want } ``` In this example, I would like to get the value `2`. Is this possible? Here is what I tried: ``` public static void getMoviedata(string KeyVal) { if (Enum.IsDefined(typeof(TestAppAreana.MovieList.Movies), KeyVal)) { //Can print the name but not value ((TestAppAreana.MovieList.Movies)2).ToString(); //list Enum.GetName(typeof(TestAppAreana.MovieList.Movies), 2); } } ```