编译以下内容时,它将根据定义的指令返回不同的值。
// 用/ d:A或/ d:B编译以查看差异
string SomeFunction()
{
#if A
return "A";
#elif B
return "B";
#else
return "C";
#endif
}条件表达式通常用于记录调试构建的其他信息。
void SomeFunc()
{
try
{
SomeRiskyMethod();
}
catch (ArgumentException ex)
{
#if DEBUG
log.Error("SomeFunc", ex);
#endif
HandleException(ex);
}
}