By JakeMangan


2018-12-06 15:07:56 8 Comments

I have an enum defined as below:

public enum colors 
{
    red = 0,
    blue = 1,
    green = 2
}

If I have a class that holds the above enum as a property, I want to be able to get the string associated with a particular enum value.

So if class.Colors = 1 then I want to return blue.

I thought the following would give me what I wanted, but it just returns a string of the integer value.

var color = class.Color.toString();

What should I use instead?

0 comments

Related Questions

Sponsored Content

9 Answered Questions

[SOLVED] What are the correct version numbers for C#?

59 Answered Questions

[SOLVED] What is the difference between String and string in C#?

26 Answered Questions

[SOLVED] How do I enumerate an enum in C#?

28 Answered Questions

[SOLVED] How do I generate a random int number?

  • 2010-04-24 23:09:11
  • Rella
  • 1964750 View
  • 1657 Score
  • 28 Answer
  • Tags:   c# random

8 Answered Questions

[SOLVED] How to loop through all enum values in C#?

26 Answered Questions

[SOLVED] Get int value from enum in C#

  • 2009-06-03 06:46:39
  • jim
  • 1270160 View
  • 1554 Score
  • 26 Answer
  • Tags:   c# enums casting int

24 Answered Questions

[SOLVED] Cast int to enum in C#

  • 2008-08-27 03:58:21
  • lomaxx
  • 1154271 View
  • 2819 Score
  • 24 Answer
  • Tags:   c# enums casting

11 Answered Questions

[SOLVED] What does the [Flags] Enum Attribute mean in C#?

  • 2008-08-12 04:09:16
  • Brian Leahy
  • 424481 View
  • 1281 Score
  • 11 Answer
  • Tags:   c# enums flags

38 Answered Questions

26 Answered Questions

[SOLVED] Why not inherit from List<T>?

Sponsored Content