Convert a string to an enum in C#

Convert a string to an enum in C#

 

public enum FilterMethod  
{  
a,  
b,  
c,  
d
}  

// Convert from Enum to String 
SortByList.Items.Clear();   
foreach (string item in Enum.GetNames(typeof(FilterMethod)))  
{  
SortByList.Items.Add(item);  
} 


// Convert from String to Enum  
Developer.SortingBy = (SortFilter)Enum.Parse(typeof(FilterMethod), "b");

2021-10-03