更新:2007 年 11 月
错误消息
无法用“method”创建委托,因为它具有 Conditional 属性
无法用条件方法创建委托,因为在某些版本中可能不存在该方法。
下面的示例生成 CS1618:
// CS1618.cs
using System;
using System.Diagnostics;
delegate void del();
class MakeAnError {
public static void Main() {
del d = new del(ConditionalMethod); // CS1618
// Invalid because on builds where DEBUG is not set,
// there will be no "ConditionalMethod".
}
// To fix the error, remove the next line:
[Conditional("DEBUG")]
public static void ConditionalMethod()
{
Console.WriteLine("Do something only in debug");
}
}