masoud ramezani masoud ramezani - 2 months ago 9
C# Question

What is the usage of #if DEBUG pre-processor directive in C#? When must we use this?

What is the usage of

#if DEBUG
pre-processor directive in C#? When must we use this?

Answer

In Debug mode:

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

Output as

Debug version
Output

In Release mode:

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

Output as

   Output

read this: #if (C# Reference)

Usage: If you have a set of values to be tested in the debug mode and not in the release mode you can use #if DEBUG

Comments