-4

I have an Enum

public enum MyEnum
    {
        value1= 1,
        value2= 2,
        value3= 3,
        value4= 4
    }

How do I get the integer values , if I give the string as input , say input--> value2 , then , output-->2

Thanks

1

1 Answer 1

2

Basically you cam use Enum.Parse to parse the string and then cast to int like below :

var str  = "value1";
var value = (int)Enum.Parse<MyEnum>(str);

Fiddle

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.