Csharp/C#教程:如何在此代码示例中获取NullReferenceException?分享


如何在此代码示例中获取NullReferenceException?

??? o = new ???(); Console.WriteLine("ToString() -> " + o.ToString() ); // ' Console.WriteLine("GetType() -> " + o.GetType()); //<--- NullReferenceException 

输出:

 ToString() -> Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object. at System.Object.GetType() at Program.Main(String[] args) 

什么是??? 为什么o.ToString()返回string.Emptyo.GetType()会抛出NullReferenceException

注意GetType()未在???重新定义 类型。

任何Nullable

检查Gravell的例子到C#中的奇怪角点案例

上述就是C#学习教程:如何在此代码示例中获取NullReferenceException?分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请点击右边联系管理员删除。

如若转载,请注明出处:https://www.ctvol.com/cdevelopment/1030961.html

(0)
上一篇 2022年1月13日
下一篇 2022年1月13日

精彩推荐