#if preprocessor directive

G

Guest

Hi everyone,

When I compile in Visual Studio as DEBUG, I see the line "Debugging..." when
I execute the program.
But when I compile as a Release, I also see this "Debugging..." line when I
execute the program. What is the cause of this problem?

best regards,

Filip De Backer



*****************************************
#define DEBUGGING

using System;
using System.Collections.Generic;
using System.Text;

namespace ProgrammingTest
{
class Program
{

#if DEBUGGING
static void OutputLocals()
{
Console.WriteLine("debugging...");
Console.ReadLine();
}
#endif

static void Main(string[] args)
{
#if DEBUGGING
OutputLocals();
#endif
}
}
}
********************************************
 
M

Mattias Sjögren

Filip,
But when I compile as a Release, I also see this "Debugging..." line when I
execute the program. What is the cause of this problem?

Well you define the symbol DEBUGGING in your source file so it will be
set regardless which build configuration you use. Why not use the
predefined DEBUG symbol instead?


Mattias
 
G

Guest

OK, the following code works:
(the previous code is something I found in a book, so that's why I asked it.
wrong code in the book :-(

*****

using System;
using System.Collections.Generic;
using System.Text;

namespace ProgrammingTest
{
class Program
{

#if DEBUG
static void OutputLocals()
{
Console.WriteLine("debugging...");
Console.ReadLine();
}
#endif

static void Main(string[] args)
{
#if DEBUG
OutputLocals();
#endif
}
}
}

***
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top