Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When #if DEBUG runs

Tags:

c#

.net

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 = "http://www.b.com//"; #endif 

What I wanted to ask is when does the

#if DEBUG 

path in the code get executed?

Does it get executed

  1. When I run up a debug session in Visual Studio?
  2. When I manually run the exe or dll in question from the debug folder?
  3. Any other circumstances I forgot to mention?
like image 830
Sachin Kainth Avatar asked Oct 18 '12 17:10

Sachin Kainth


People also ask

How do you use the word when?

We use when to mean '(at) the time that'. We use since to refer to a particular time in the past until another time or until now: I had a great time when I went to the coast.

What does when's mean?

contraction of when is:When's the show over? contraction of when does:When's the next train leave? contraction of when has:When's he ever been an authority?

What is the example of when?

It was a time when people didn't have to lock their doors. the happy days when we were together We're still waiting for the test results, when we'll decide our next move. Conjunction When he finally showed up, he was drunk. When I was in school, we didn't have computers.

What is a synonym for when?

at the same time as. at the time. for the time being. in the course of.


2 Answers

#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: 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//"; 
like image 155
Danpe Avatar answered Sep 21 '22 04:09

Danpe


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.

like image 37
Brian Rasmussen Avatar answered Sep 24 '22 04:09

Brian Rasmussen