Sambo
Sambo

Reputation: 1472

Is there a way in C# to replicate a '#ifndef _DEBUG' from C/C++?

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++?

Upvotes: 41

Views: 18704

Answers (3)

Dave Markle
Dave Markle

Reputation: 97791

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

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

See this.

Upvotes: 67

Tone
Tone

Reputation: 322

Yes you can use preprocessors in C#.

Here is a list from msdn

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

Upvotes: 4

EricSchaefer
EricSchaefer

Reputation: 26370

#if !DEBUG
     // whatever
#endif

Upvotes: 5

Related Questions