Wednesday, September 28, 2016

How to Cast int to enum and back in C#?

How to Cast int to enum and back in C#

To cast an int to enum just do the bellow

MyEnum foo = (MyEnum)myInt;                        

To cast to enum from a string value do the below


MyEnum foo = (MyEnum) Enum.Parse(typeof(MyEnum), myString)

No comments:

Post a Comment