Home How to turn Integer to enumeration value
Reply: 1

How to turn Integer to enumeration value

fexum
1#
fexum Published in 2018-02-14 05:05:55Z

This question already has an answer here:

  • Cast int to enum in C# 21 answers

Lets say I have an enum like this...

internal enum SomeType
{
    Type1 = 0, 
    Type2 = 1, 
    Type3 = 2
}

and I had an int like this...

int i = 1; // would return Type2...

How do I convert that int to the enum value?

Praveen Paulose
2#
Praveen Paulose Reply to 2018-02-14 05:09:17Z

You can cast it directly

SomeType someType = (SomeType)i;
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.321689 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO