首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >(此==为空)在C#中!

(此==为空)在C#中!
EN

Stack Overflow用户
提问于 2009-10-21 20:57:11
回答 3查看 14.2K关注 0票数 132

由于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

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1600662

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档