我努力學習預處理指令,所以我做了一個簡單的例子是這樣的:預處理指令不可能定義或取消定義預處理
using System;
namespace learning
{
class Program
{
static void Main(string[] args)
{
#define DEBUG
test();
}
private void test()
{
#if DEBUG
Console.WriteLine("Debug mode");
#elif RELEASE
Console.WriteLine("Release mode");
#else
Console.WriteLine("Debug and release don't defined");
#endif
}
}
}
,但我遺憾的是這個錯誤:
Impossible to define or cancel defining the preprocessor symbols after the first token in the file
我從一本編程書籍中拿這個例子,有什麼不對?
更新(我的溶液):
#define RELEASE
using System;
namespace learning
{
class Program
{
static void Main(string[] args)
{
#if DEBUG
Console.WriteLine("Debug mode");
#elif RELEASE
Console.WriteLine("Release mode");
#else
Console.WriteLine("Debug and release don't defined");
#endif
Console.ReadLine();
}
}
}
打印結果:Debug mode
,但應該是Release mode
。我做錯了什麼?
將#define DEBUG放在文件的開頭。 – neo
這本書是錯誤的,基本上。它是哪本書?名字和恥辱...(我真的希望它不是我的...) –
@JonSkeet http://antoniopelleriti.it/page/libro-csharp – Dillinger