1

I have an enum with Description attributes like this:

public enum MyEnum
{
    Name1 = 1,
    [Description("Here is another")]
    HereIsAnother = 2,
    [Description("Last one")]
    LastOne = 3
}

I have value of "Last one" that is 3

What is the code that return that?

Vishal Suthar
  • 17,013
  • 3
  • 59
  • 105
oliver
  • 362
  • 2
  • 5
  • 13

1 Answers1

1

You can do it like this

int lastOneValue = (int) MyEnum.LastOne;

This code returns the value 2 instead of "LastOne"

string lastOneString = MyEnum.LastOne.ToString();

This code returns "LastOne" as a string value

MyEnum mynum = MyEnum.LastOne;

This code creates new object of MyEnum and sets his value to 'LastOne'

Silagy
  • 3,053
  • 2
  • 27
  • 39