I have this code in my C# class.
#if DEBUG
private const string BASE_URL = \"http://www.a.com/\";
#else
private const string BASE_URL = \"h
#if DEBUG
It's a preprocessor definition.
It compiles when you define DEBUG constant. And yes, it's default on Debug Build Configuration.
Visual Studio 2010 Project Properties:
If Define DEBUG constant
is checked VS will compile:
private const string BASE_URL = "http://www.a.com/";
Else (not checked) VS will compile:
private const string BASE_URL = "http://www.b.com//";
That is a "compiler directive", which means it will actually include or exclude the code from the build process (or compiling) based on the #if's that you put in. That being said, the DEBUG symbol is in the properties of your project, and in Visual Studio is generally removed automatically on the "Release" build.
So basically, it doesn't have to be in Visual studio running in debug, and it does not have to be in any certain folder, your code is just built that way.
It's a preprocessor directive. The code in the DEBUG part is compiled when you do a debug build (more specifically when the DEBUG constant is defined). I.e. if you do a debug build BASE_URL will point to www.a.com. Otherwise it will point to www.b.com.
If you are compiling with the DEBUG configuration, the code before the else line will get compiled while the other will not. If you compile in any other configuration, the second line will be compiled while the first will not.
VS 2017 actually sense the active configuration and for example will gray out the debug condition if the release configuration is selected.
Go to "Project Properties"--> Build Tab of the application. If the Configuration: Active (Debug) then Debug configuration is enabled. Below code will print to console.
#if DEBUG
Console.WriteLine("in debug mode...");
#endif
If Configuration: Active(Release) then Release configuration is enabled.Below code will print to console.
#if RELEASE
Console.WriteLine("in release mode...");
#endif
If you want to switch between DEBUG and RELEASE mode use the "Debug/Release/Configuration Manager" drop down right under the Tools Menu.Apologies as most of the developer know it...but is sometimes overlooked and causes confusion why above code is not running correctly.