how to get Enum content via setting value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Le Bien
    New Member
    • Mar 2012
    • 1

    how to get Enum content via setting value

    I want to get the content of Enum type by corresponding value.
    For example
    Code:
    public enum color
    {
        red = 1 , yellow = 2 , green = 3
    
    }
    How can I get the color via value 1 , 2 , 3.
    Last edited by Frinavale; Mar 22 '12, 04:23 PM. Reason: Added code tags.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Use the Enum.GetValues Method to get the "values" for the enums.

    Use the Enum.GetNames Method to get the "names" of the enums.

    Use the Enum.Parse Method convert the string representation of the name or numeric value of one or more enumerated constants to an equivalent enumerated object.

    -Frinny

    Comment

    Working...