if的作用是程序流控制,会直接编译、执行。
#if是对编译器的指令,其作用是告诉编译器,有些语句行希望在条件满足时才编译。
#if DEBUG //todo #endif #if !DEBUG //todo #endif #warning description
#define VC_V7 #if (DEBUG && !VC_V7) Console.WriteLine("DEBUG is defined"); #elif (!DEBUG && VC_V7) Console.WriteLine("VC_V7 is defined"); #elif (DEBUG && VC_V7) Console.WriteLine("DEBUG and VC_V7 are defined"); #else Console.WriteLine("DEBUG and VC_V7 are not defined"); #endif