??? o = new ???(); Console.WriteLine("ToString() -> " + o.ToString() ); //<--- Prints '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.Empty和o.GetType()会抛出NullReferenceException?
Note:
GetType()
is not redefined in the???
type.
解决方法
任何Nullable< T>.