2012年12月21日

C#中把null作为参数传过去会调用哪个overload?

摘要: Stack Overflow上有个有趣的问题,如果向下面这么写,没问题。Console.WriteLine( String.Format( "{0}", (object)null) );但是如果这么写,会出一个ArgumentNullException。Console.WriteLine( String.Format( "{0}", null) );原因在于C#编译器会把null转换成最容易转到的类型,因为Fromat函数有下面几个重载:Format(String, Object)Format(String, Object[])Format(IForma 阅读全文

posted @ 2012-12-21 13:33 fresky 阅读(287) 评论(0) 推荐(0) 编辑

导航