#if preprocessor directive

  • Thread starter Thread starter Guest
  • Start date Start date
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
}
}
}
********************************************
 
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
 
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
}
}
}

***
 
Back
Top