I have a simple Enum
public enum TestEnum
{
TestOne = 3,
TestTwo = 4
}
var testing = TestEnum.TestOne;
And I want to retrieve its value (3) via reflection. Any ideas on how to do this?
Thanks Mat
I have a simple Enum
public enum TestEnum
{
TestOne = 3,
TestTwo = 4
}
var testing = TestEnum.TestOne;
And I want to retrieve its value (3) via reflection. Any ideas on how to do this?
Thanks Mat
Why do you need reflection?
int value = (int)TestEnum.TestOne;
Full code : How to Get Enum Values with Reflection in C#
MemberInfo[] memberInfos = typeof(MyEnum).GetMembers(BindingFlags.Public | BindingFlags.Static);
string alerta = "";
for (int i = 0; i < memberInfos.Length; i++) {
alerta += memberInfos[i].Name + " - ";
alerta += memberInfos[i].GetType().Name + "\n";
}
this article is best for you using reflection with Enums: Enum Reflection