开发者

Retrieve integer value of enum

开发者 https://www.devze.com 2023-02-05 03:41 出处:网络
Given: public enum myType { Val1 = 1, Val2 = 2, Val3 = 3 } 开发者_如何学JAVAand code elsewhere in the app where a value :

Given:

public enum myType
{
    Val1 = 1,
    Val2 = 2,
    Val3 = 3
}
开发者_如何学JAVA

and code elsewhere in the app where a value : ... row.myType // resolves to Val1 ...

I need to translate row.myType to 1


Simply cast to an int:

int enumValue = (int)row.MyTime;


cast it to int

(int)row.myTime


You can simply cast it to an integer:

(int)row.myType;


myType someEnumVal = myType.Val1;
int intValOfEnum = (int)someEnumVal;
0

精彩评论

暂无评论...
验证码 换一张
取 消