Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 926
Sambo Avatar asked Feb 17 '10 11:02

Sambo


People also ask

What \r mean in C?

\r is known as carriage return. \r is used in C language to move the cursor to the beginning of the current line that you are working on.

Is it better to learn C or C++?

Compared to C++, C is the simpler and ultimately faster programming language. C is procedural and does not support classes and objects, meaning it has less functionality than C++. This allows you to spend more time focusing on what you can do with C's libraries, especially at the OS level.

What does =& mean in C?

The bitwise AND operator (&) compares each bit of the first operand to that bit of the second operand. If both bits are 1, the bit is set to 1. Otherwise, the bit is set to 0.

Does \n work in C?

In most C compilers, including ours, the newline escape sequence '\n' yields an ASCII line feed character. The C escape sequence for a carriage return is '\r'.


2 Answers

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

See this.

like image 165
Dave Markle Avatar answered Sep 23 '22 21:09

Dave Markle


#if !DEBUG      // whatever #endif 
like image 23
EricSchaefer Avatar answered Sep 21 '22 21:09

EricSchaefer