C # debug and release mode

How to find if it is in debug mode or release mode? Are there any other ways to find it?

    #if(DEBUG)
{
       Console.WriteLine("Debug mode");
       //Or Things to do in debug mode
}
    #else
{
       Console.WriteLine("Release mode");
       //Or Things to do in Release mode- May be to change the text, image 
}
#endif
+4
source share
2 answers

No, this is the only way, but you need the correct syntax and capitalization. You can also check if the debugger is connected. Here is the correct syntax:

#if DEBUG
    Console.Writeline("debug");
#else
    Console.Writeline("release");
#endif
    // You can also check if a debugger is attached, which can happen in either debug or release
    if (Debugger.IsAttached)
        Console.WriteLine("debugger attached");
+6
source

You can try using System.Diagnostics:

if (Debugger.IsAttached) {...?

+1
source

All Articles