Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. getting enum integer ?

getting enum integer ?

Scheduled Pinned Locked Moved C#
question
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    azusakt
    wrote on last edited by
    #1

    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

    N U 2 Replies Last reply
    0
    • A azusakt

      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

      N Offline
      N Offline
      Nick Parker
      wrote on last edited by
      #2

      azusakt 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

      1 Reply Last reply
      0
      • A azusakt

        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

        U Offline
        U Offline
        User 260964
        wrote on last edited by
        #3

        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 even string. But I suggest int, 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.

        H 1 Reply Last reply
        0
        • U User 260964

          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 even string. But I suggest int, 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.

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          Actually, enum values automatically derive from int. And you can't use string (this is well documented in the Enum 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 a short, 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-----

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups