Possible Duplicate:
Using GetHashCode for getting Enum int value
Is it safe to use GetHasCode to get a enumeration value like the code below:
myList.SelectedIndex = myEnumValue.GetHashCode()
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.
No. The result isn’t guaranteed to be unique or equivalent to the integral value of that enum value.
I think it is currently implemented to be the same as a cast to int. But that’s an implementation detail and may change at any time.
The correct way is to cast to the underlying integral type: