Skip to content

Instantly share code, notes, and snippets.

@tugberkugurlu
Created November 26, 2013 15:21
Show Gist options
  • Save tugberkugurlu/7660247 to your computer and use it in GitHub Desktop.
Save tugberkugurlu/7660247 to your computer and use it in GitHub Desktop.
Get Enum names and values
public enum MyEnum : byte
{
A = 0,
B = 1,
C = 2
}
Array enumNames = Enum.GetNames(typeof(MyEnum));
Array enumValues = Enum.GetValues(typeof(MyEnum));
for (int i = 0; i < enumValues.Length; i++)
{
Type underlyingType = Enum.GetUnderlyingType(typeof(MyEnum));
object value = enumValues.GetValue(i);
object convertedValue = Convert.ChangeType(value, underlyingType);
Console.WriteLine(enumNames.GetValue(i).ToString() + ": " + convertedValue.ToString());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment