Getting back int value from Enum? 
Author Message
 Getting back int value from Enum?

__value enum Test { ONE=1, FIVE=5, SIX=6 };

Array* pTest = System::Enum::GetValues(__typeof(Test));
int __gc* pInts = new __gc[pTest->Length];

// Store actual int values, and display the string version of the enum
values
for (int i=0; i<pTest ->Length; i++)
{
    // Display string version
    Console::WriteLine(pArr->GetValue(i));

    // Store actual int value
    pInts[i] = <how to get the int value??>

Quote:
}

`
Thanks,
TJ


Fri, 25 Nov 2005 01:14:44 GMT  
 Getting back int value from Enum?
Soren,

Quote:
> __value enum Test { ONE=1, FIVE=5, SIX=6 };

> Array* pTest = System::Enum::GetValues(__typeof(Test));
> int __gc* pInts = new __gc[pTest->Length];

> // Store actual int values, and display the string version of the enum
> values
> for (int i=0; i<pTest ->Length; i++)
> {
>     // Display string version
>     Console::WriteLine(pArr->GetValue(i));

>     // Store actual int value
>     pInts[i] = <how to get the int value??>
> }

Simple casting. GetValue() will return the actual value, but with the Enum
type. Just cast that to int to get the integral value. Consider this simple
example:

#using <mscorlib.dll>
using namespace System;

__value enum Test { ONE=1, FIVE=5, SIX=6 };

int main()
{
Test values[] = dynamic_cast<Test[]>(Enum::GetValues(__typeof(Test)));
for ( int i=0; i < values->Length; i++ ) {
   Console::WriteLine(S"{0}={1}", __box(values[i]), __box((int)values[i]));

Quote:
}
}

--
Tomas Restrepo



Fri, 25 Nov 2005 01:34:28 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Getting enum int value from mnemonic

2. Getting enum int value from mnemonic

3. Problem with getting values back from a function...

4. Getting values back from a program

5. Problem with getting values back from a function....

6. getting one's place value of an unsigned int

7. enum => num back to text

8. How can I transform a int value to a char value

9. how can I get the corresponding enum value from int value.

10. treating enum as int

11. enum, int and #define

12. is enum diffrent than int?

 

 
Powered by phpBB® Forum Software