Get Enum Name
//Option 1:
string m = Enum.GetName(typeof(MyEnumClass), value);
//Option 2:
string n = nameof(MyEnumClass.Value);
Get Enum Name
//Option 1:
string m = Enum.GetName(typeof(MyEnumClass), value);
//Option 2:
string n = nameof(MyEnumClass.Value);
reflection get enum value C#
System.Type enumType = typeof(TestEnum);
System.Type enumUnderlyingType = System.Enum.GetUnderlyingType(enumType);
System.Array enumValues = System.Enum.GetValues(enumType);
for (int i=0; i < enumValues.Length; i++)
{
// Retrieve the value of the ith enum item.
object value = enumValues.GetValue(i);
// Convert the value to its underlying type (int, byte, long, ...)
object underlyingValue = System.Convert.ChangeType(value, enumUnderlyingType);
System.Console.WriteLine(underlyingValue);
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us