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. C++ define statements == what in C#?

C++ define statements == what in C#?

Scheduled Pinned Locked Moved C#
csharpc++question
6 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.
  • D Offline
    D Offline
    dazinith
    wrote on last edited by
    #1

    in C++ i would have something like this:

    #define DIALUP 0
    #define FTP 1
    ..
    if (m_nAccessMode == FTP)
    ..

    this was really useful for keeping track of options and such, like if im storing a combo box of Monthly,Quarterly,Annually i dont wanna just compare strings when im doing an if statement, but rather use some sort of defined key so that i never get my stuff mixed up.. i have looked at the #define statement in C# and it only lets me define like

    #define FTP

    it doesnt let me assign a value to it in the define statement, so i really dont even see its purpose :confused: .. can someone set me straight plz? still a newb.. cut me some slack :P -dz

    R K 2 Replies Last reply
    0
    • D dazinith

      in C++ i would have something like this:

      #define DIALUP 0
      #define FTP 1
      ..
      if (m_nAccessMode == FTP)
      ..

      this was really useful for keeping track of options and such, like if im storing a combo box of Monthly,Quarterly,Annually i dont wanna just compare strings when im doing an if statement, but rather use some sort of defined key so that i never get my stuff mixed up.. i have looked at the #define statement in C# and it only lets me define like

      #define FTP

      it doesnt let me assign a value to it in the define statement, so i really dont even see its purpose :confused: .. can someone set me straight plz? still a newb.. cut me some slack :P -dz

      R Offline
      R Offline
      RB Emphasys
      wrote on last edited by
      #2

      it sounds like your trying to do an enumeration. enum Days {Sat=1, Sun, Mon, Tue, Wed, Thu, Fri}; If you look it up at msdn youll be all set. Ryan

      D L 2 Replies Last reply
      0
      • R RB Emphasys

        it sounds like your trying to do an enumeration. enum Days {Sat=1, Sun, Mon, Tue, Wed, Thu, Fri}; If you look it up at msdn youll be all set. Ryan

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

        works great.. i see that i can use this outside of the class name, and inside the namespace such that i can use it throughout the namespace.. thats just what i needed, thanks a ton! :) still a newb.. cut me some slack :P -dz

        1 Reply Last reply
        0
        • D dazinith

          in C++ i would have something like this:

          #define DIALUP 0
          #define FTP 1
          ..
          if (m_nAccessMode == FTP)
          ..

          this was really useful for keeping track of options and such, like if im storing a combo box of Monthly,Quarterly,Annually i dont wanna just compare strings when im doing an if statement, but rather use some sort of defined key so that i never get my stuff mixed up.. i have looked at the #define statement in C# and it only lets me define like

          #define FTP

          it doesnt let me assign a value to it in the define statement, so i really dont even see its purpose :confused: .. can someone set me straight plz? still a newb.. cut me some slack :P -dz

          K Offline
          K Offline
          Kevin McFarlane
          wrote on last edited by
          #4

          This is actually bad practice in C++. You should use const declarations instead. const int DIALUP = 0; or enums, as another poster has suggested. The #define in C# is for conditional compilation. And it should be used like this in C++ also. See, for example, Scott Meyers's "Effective C++" Kevin

          1 Reply Last reply
          0
          • R RB Emphasys

            it sounds like your trying to do an enumeration. enum Days {Sat=1, Sun, Mon, Tue, Wed, Thu, Fri}; If you look it up at msdn youll be all set. Ryan

            L Offline
            L Offline
            leppie
            wrote on last edited by
            #5

            Any reasons C/C++ programmers steer away from enums? All I ever see is defines... Hey leppie! Your "proof" seems brilliant and absurd at the same time. - Vikram Punathambekar 28 Apr '03

            K 1 Reply Last reply
            0
            • L leppie

              Any reasons C/C++ programmers steer away from enums? All I ever see is defines... Hey leppie! Your "proof" seems brilliant and absurd at the same time. - Vikram Punathambekar 28 Apr '03

              K Offline
              K Offline
              Kevin McFarlane
              wrote on last edited by
              #6

              In pure C programs you should expect to see lots of #defines. In pure C++ programs you should expect to see none (it's poor practice - see http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.7[^]) but you often do. Kevin

              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