getting enum integer ?
-
Hi all, I'm having a stupid question, how can I get the integer that represent the enum?
public enum outputType { TIF = 0, JPG, BMP, none }
I would like to get the integer of this enum, somethings like int num = (int)outputType.JPG; how can I do it? Thank you -
Hi all, I'm having a stupid question, how can I get the integer that represent the enum?
public enum outputType { TIF = 0, JPG, BMP, none }
I would like to get the integer of this enum, somethings like int num = (int)outputType.JPG; how can I do it? Thank youazusakt wrote: int num = (int)outputType.JPG; That works for me, did you try this? :confused: -Nick Parker
Last time I checked, all programmers have selective ignorance. I know nothing about 3D graphics. I know a lot about COM. VB gets under people's skin because one can be ignorant of computer architecture and ASM and still get a lot done. - Don Box
-
Hi all, I'm having a stupid question, how can I get the integer that represent the enum?
public enum outputType { TIF = 0, JPG, BMP, none }
I would like to get the integer of this enum, somethings like int num = (int)outputType.JPG; how can I do it? Thank youTry this:
public enum OutputType : int
{
None = 0,
TIFF = 1,
JPEG = 2,
BMP = 3
}
[...]
int num = (int)OutputType.JPEG;You can also use
uint
,long
,char
,ulong
,byte
,ubyte
,decimal
,double
,float
, and maybe evenstring
. But I suggestint
, since it doesn't put such a heavy load on the processor. - Daniël Pelsmaeker
One fool can ask more questions than all the wise men can answer.
-
Try this:
public enum OutputType : int
{
None = 0,
TIFF = 1,
JPEG = 2,
BMP = 3
}
[...]
int num = (int)OutputType.JPEG;You can also use
uint
,long
,char
,ulong
,byte
,ubyte
,decimal
,double
,float
, and maybe evenstring
. But I suggestint
, since it doesn't put such a heavy load on the processor. - Daniël Pelsmaeker
One fool can ask more questions than all the wise men can answer.
Actually, enum values automatically derive from
int
. And you can't usestring
(this is well documented in theEnum
Type documentation). Besides, this isn't necessary. The cast is the important thing, and so long as you don't overflow or anything like that. For instance, in your example, all the numbers are small and possitive so you could still cast to ashort
,long
or whatever.-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----