开发者

Retrieve integer value of enum

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜