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?

0

1 Answer 1

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'

Sign up to request clarification or add additional context in comments.

1 Comment

Vishal might have been talking about the Description, as how to get that.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.