how to pass string value to enum in csharp

Code Example - how to pass string value to enum in csharp

                
                        MyEnum myEnum = (MyEnum)Enum.Parse(typeof(MyEnum), myString);
                    
                
 

csharp .net core convert string to enum

                        
                                var foo = (YourEnum) Enum.Parse(typeof(YourEnum), yourString);
if (Enum.IsDefined(typeof(YourEnum), foo))
{
    return foo;
}
                            
                        
 

csharp get enum value from string

                        
                                //This example will parse a string to a Keys value
Keys key = (Keys)Enum.Parse(typeof(Keys), "Space");
//The key value will now be Keys.Space
                            
                        
 

csharp get enum name from value

                        
                                string name=(weekdays)2;//returns weekdays which has value 2.Here weekdays is enum name