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. #define in C#

#define in C#

Scheduled Pinned Locked Moved C#
csharpc++question
4 Posts 3 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.
  • Z Offline
    Z Offline
    zecodela
    wrote on last edited by
    #1

    hi, i want to know any method to implement #define similar thing in C#. i need to declare some const like below in C++ #define STATUS_A 'a' currently, i used public const char STATUS_A = 'a'; or enum STATUS { A = 'a'; } apart from above methods, any other method? thanks, jim

    D 1 Reply Last reply
    0
    • Z zecodela

      hi, i want to know any method to implement #define similar thing in C#. i need to declare some const like below in C++ #define STATUS_A 'a' currently, i used public const char STATUS_A = 'a'; or enum STATUS { A = 'a'; } apart from above methods, any other method? thanks, jim

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      You already found it. C# doesn't support compiler directives. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

      M 1 Reply Last reply
      0
      • D Dave Kreskowiak

        You already found it. C# doesn't support compiler directives. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

        M Offline
        M Offline
        mav northwind
        wrote on last edited by
        #3

        Not quite. You can use defines in C# as well, although not exactly like in C/C++. You _can_ define symbols at the very beginning of a C# file (before any using directives) or in the project settings in VS.NET. In your code you can use #if, #elif, #else and #endif and some other preprocessor directives to compile or not compile part of your code, depending on the symbols you define. MSDN has a list: C# preprocessor directives[^] Regards, mav

        D 1 Reply Last reply
        0
        • M mav northwind

          Not quite. You can use defines in C# as well, although not exactly like in C/C++. You _can_ define symbols at the very beginning of a C# file (before any using directives) or in the project settings in VS.NET. In your code you can use #if, #elif, #else and #endif and some other preprocessor directives to compile or not compile part of your code, depending on the symbols you define. MSDN has a list: C# preprocessor directives[^] Regards, mav

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          My bad! :-> I could have sworn that it didn't. This topic came up before about 6 months ago and I thought that was what the answer was. :-D RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

          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