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

11 Answered Questions

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

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

28 Answered Questions

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

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

22 Answered Questions

[SOLVED] Cast int to enum in C#

  • 2008-08-27 03:58:21
  • lomaxx
  • 1088578 View
  • 2706 Score
  • 22 Answer
  • Tags:   c# enums casting

57 Answered Questions

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

25 Answered Questions

[SOLVED] Get int value from enum in C#

  • 2009-06-03 06:46:39
  • jim
  • 1189254 View
  • 1466 Score
  • 25 Answer
  • Tags:   c# enums casting int

26 Answered Questions

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

9 Answered Questions

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

38 Answered Questions

8 Answered Questions

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

26 Answered Questions

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

Sponsored Content