enumeration help

  • Thread starter Thread starter Luke Smith
  • Start date Start date
L

Luke Smith

i have the following

enum length { metres = 0, centimetres, millimetres }

By knowing the integer (0, 1 2 ....) how do i obtain the name (metres,
centimetres....)??

thanks
 
Just cast the integer value to your enum value. example

enum length
{
metres = 0,
centimetres = 1,
millimetres = 2
}

//in the method
public void test()
{
length x = length.centimetres;
int a = (int) x; // a becomes 1;

int b = 0;
length y = (length) b; // y becomes length.metres
}


hth

Fitim Skenderi
 
Back
Top