How to retrieve an Enum member by their Name?

 Posted by vishalneeraj-24503 on 8/5/2014 | Category: Visual Studio Interview questions | Views: 477 | Points: 40
Answer:

To retrieve an Enum member given by their Name,we will use the ConvertFrom() method of the TypeConverter class and cast the result to our Enum type as

'VB.Net
enum_obj = CType(System.ComponentModel.TypeDescriptor.GetConverter(enum_obj).ConvertFrom("Active"),Active_Inactive)

MasBox(enum_obj.ToString())

//C#
enum_obj = (Active_Inactive)TypeDescriptor.GetConverter(enum_obj).ConvertFrom("Active");

MessageBox.Show(enum_obj.ToString());


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response