How to convert string to Enum ?

Please refer below example for answer :
public enum MonthEnum
{
  January = 1,
  February = 2,
  March = 3,
  April = 4,
  May = 5,
  June = 6,
  July = 7,
  August = 8,
  September = 9,
  October = 10,
 November = 11,
 December =12
 
}

To Convert string value to enum instance use below :
Month may= (MonthEnum)Enum.Parse(typeof(MonthEnum), "May");

No comments:

Popular Posts