vendredi 21 février 2020

How would I convert a int to enum value at runtime when I have a string and an integer?

What I have is a string variable that is the name of a enum. I have the integer of the enum. How would I convert that into instance of the enum itself?

Enum TestEnum
    {
        One = 1,
        Two = 2,
        Three = 3
    }

string str = "TestEnum";
int intValue = 2;

I see many posts that require you to have an instance of the enum to get it's like this highly upvoted answer.

I need to do this at runtime.





Aucun commentaire:

Enregistrer un commentaire