由于C# 4中修复了一个错误,下面的程序打印true
。(在LINQPad中试用)
void Main() { new Derived(); }
class Base {
public Base(Func<string> valueMaker) { Console.WriteLine(valueMaker()); }
}
class Derived : Base {
string CheckNull() { return "Am I null? " + (this == null); }
public Derived() : base(() => CheckNull()) { }
}
在处于发布模式的VS2008中,它抛出一个InvalidProgramException。(在调试模式下,它可以正常工作)
在VS2010 Beta2中,它不能编译(我没有尝试Beta1);我以一种艰难的方式了解到这一点
有没有其他方法可以用纯C#来制作this == null
?
https://stackoverflow.com/questions/1600662
复制相似问题