Question:
This question deeply explores the integer values of retrieval with enumeration. Consider the following scenes: a class named contains an enumeration called
, which means various survey issues. Is there a direct method to obtain an integer value of specific enumeration members and use it in functions such as? Questions
Question
Answer: Questions.Get(Question.Role)
To extract the integer value from the enumeration, just convert it for mandatory. For example:
This forced conversion can perfectly cooperate with the vast majority of enumeration, because they usually useas their underlying type.
<code class="language-csharp">int something = (int)Question.Role;</code>
or int
and other types, it must be forced to convert it into an enumerated underlying type. For example, consider the following enumeration:
uint
In this case, the correct mandatory conversion will be: long
ulong
<code class="language-csharp">enum StarsInMilkyWay:long {Sun = 1, V645Centauri = 2, ..., Wolf424B = 2147483649};</code>
The above is the detailed content of How Can I Retrieve the Integer Value of a C# Enum Member?. For more information, please follow other related articles on the PHP Chinese website!