Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Debug and release mode

Tags:

c#

How to find whether 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
like image 528
Dev Avatar asked Mar 23 '23 06:03

Dev


2 Answers

No that's the only way, but you need to have the syntax and capitalization correct. You can also check whether the debugger is attached. 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");
like image 135
Alan Avatar answered Apr 06 '23 19:04

Alan


You could try using System.Diagnostics:

if (Debugger.IsAttached) {... ?

like image 41
davbryn Avatar answered Apr 06 '23 18:04

davbryn