justSteve
justSteve

Reputation: 5524

Retrieve integer value of enum

Given:

public enum myType
{
    Val1 = 1,
    Val2 = 2,
    Val3 = 3
}

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

I need to translate row.myType to 1

Upvotes: 0

Views: 121

Answers (4)

Mads
Mads

Reputation: 1206

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

Upvotes: 0

Willem van Rumpt
Willem van Rumpt

Reputation: 6570

You can simply cast it to an integer:

(int)row.myType;

Upvotes: 0

Oded
Oded

Reputation: 499392

Simply cast to an int:

int enumValue = (int)row.MyTime;

Upvotes: 1

Dani
Dani

Reputation: 15081

cast it to int

(int)row.myTime

Upvotes: 0

Related Questions