views:

245

answers:

3

I'd like to conditionally exclude/include code based on whether I'm building in debug mode.

Can I use something as simple as a #ifndef _DEBUG as I would in C++?

+7  A: 
#if DEBUG
    Console.WriteLine("Debug version");
#endif

#if !DEBUG
    Console.WriteLine("NOT Debug version");
#endif

See this.

Dave Markle
... and consider using Trace/Debug output respectively before rolling your own. Same goes for assertions.
Johannes Rudolph
A: 
#if !DEBUG
     // whatever
#endif
EricSchaefer
A: 

Yes you can use preprocessors in C#.

Here is a list from msdn

http://msdn.microsoft.com/en-us/library/ed8yd1ha(VS.71).aspx

Tone