In C# we can convert an enum to an int by static typecasting as shown below:
int res = (int)myEnum;
Is any other way to do this conversion?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There are plenty of other ways (including
Convert.ToInt32as mentioned by acrilige), but a static cast is probably the best choice (as far as readability and performance are concerned)