Preprocessor definitions in C#
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Preprocessor definitions in C#

  1. #1
    Join Date
    Dec 2009
    Posts
    11

    Question Preprocessor definitions in C#

    Is it possible to use preprocessor definitions in C# like we do in C and C++?

    Code:
    #define DEBUG
    // ...
    #ifdef DEBUG
    Console.WriteLine("This is a debug message.");
    #endif // #ifdef DEBUG

  2. #2
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Preprocessor definitions in C#

    Yes, you can define them in Properties > Build. The "DEBUG" symbol is already defined for you.
    If you liked my post go ahead and give me an upvote so that my epee.... ahem, reputation will grow.

    Yes; I have a blog too - http://the-angry-gorilla.com/

  3. #3
    Join Date
    Aug 2005
    Posts
    198

    Re: Preprocessor definitions in C#

    For your sample, the only thing that changes is "#ifdef DEBUG" becomes "#if DEBUG".

    Note that C# #define's are strictly 'flag-type' #defines - you can't specify replacements or macros as you can in C/C++.
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com
    Instant C# - VB to C# Converter
    Instant VB - C# to VB Converter

  4. #4
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: Preprocessor definitions in C#

    For conditional debugging it is possible, but nothing like C++ macros are available in C#.

    Symbol checked in #if condition can be also defined when invoking compiler from command line with /define: e.g. csc /define: DEBUG.
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center