??? o = new ???();
Console.WriteLine("ToString() -> " + o.ToString() ); //<--- Prints 'ToString() -> '
Console.WriteLine("GetType() -> " + o.GetType()); //<--- NullReferenceException
Output:
ToString() ->
Unhandled Exception: System.NullReferenceException: Object reference not set
to an instance of an object.
at System.Object.GetType()
at Program.Main(String[] args)
Question
What is the type ??? and why does o.ToString() return string.Empty and o.GetType() throws a NullReferenceException?
Note:
GetType()is not redefined in the???type.
Nullable<T>, this will happen sinceGetTypeis notvirtualand the object will have to be boxed in order to callObject.GetTypein the base class, and a nullable type will box to null, and a method call on null will cause a NullReferenceException. This is not a real question--voted to close.