Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

get int value from enum c#

public class EnumValue
{
    public string Name { get; set; }
    public int Value { get; set; }
}

public static List<EnumValue> GetValues<T>()
{
  List<EnumValue> values = new List<EnumValue>();
  foreach (var itemType in Enum.GetValues(typeof(YourEnumClass)))
  {
    //For each value of this enumeration, add a new EnumValue instance
    values.Add(new EnumValue()
               {
                 Name = Enum.GetName(typeof(YourEnumClass), itemType), 
                 Value = (int)itemType
                 });
  }
  return values;
}
Source by exceptionnotfound.net #
 
PREVIOUS NEXT
Tagged: #int #enum
ADD COMMENT
Topic
Name
2+4 =