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. How to tied enum to a class

How to tied enum to a class

Scheduled Pinned Locked Moved C#
4 Posts 2 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.
  • D Offline
    D Offline
    dino2094
    wrote on last edited by
    #1

    Lets say I have enum OutputFormat { HEX, BINARY DECIMAL } class Foo{ ... ... public void print(OutputFormat x){ .... .... } foo y = ....; y.print(OutputFormat.HEX); But I'd like to ties the enum to the class so that the call would look like y.print(Foo.OutputFormat.HEX); instead of the y.print(OutputFormat.HEX); Any ideas> Thanks

    C 1 Reply Last reply
    0
    • D dino2094

      Lets say I have enum OutputFormat { HEX, BINARY DECIMAL } class Foo{ ... ... public void print(OutputFormat x){ .... .... } foo y = ....; y.print(OutputFormat.HEX); But I'd like to ties the enum to the class so that the call would look like y.print(Foo.OutputFormat.HEX); instead of the y.print(OutputFormat.HEX); Any ideas> Thanks

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      class Foo{ public enum OutputFormat { HEX, BINARY DECIMAL } ... } You can also use private to make the enum only useful within the class.

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      D 1 Reply Last reply
      0
      • C Christian Graus

        class Foo{ public enum OutputFormat { HEX, BINARY DECIMAL } ... } You can also use private to make the enum only useful within the class.

        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

        D Offline
        D Offline
        dino2094
        wrote on last edited by
        #3

        I'm a retard. I could swear that I retried that and got a compiling error! It works now. Thank you very much, I can stop banging my head on the desk.

        C 1 Reply Last reply
        0
        • D dino2094

          I'm a retard. I could swear that I retried that and got a compiling error! It works now. Thank you very much, I can stop banging my head on the desk.

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          dino2094 wrote:

          I'm a retard.

          *grin* everyone is a retard, sometimes.

          Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

          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