#error(C# 参考)

#error 使您可以从代码中的特定位置生成错误。例如:

#error Deprecated code in this method.

备注

#error 通常用在条件指令中。

也可以用 #warning(C# 参考) 生成用户定义的警告。

// preprocessor_error.cs
// CS1029 expected
#define DEBUG
class MainClass 
{
    static void Main() 
    {
#if DEBUG
#error DEBUG is defined
#endif
    }
}

请参阅

C# 参考

C# 编程指南

C# 预处理器指令