-
April 19th, 2010, 08:04 AM
#1
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
-
April 19th, 2010, 02:19 PM
#2
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/
-
April 19th, 2010, 05:41 PM
#3
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++.
-
April 21st, 2010, 02:59 AM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|