tags:

views:

155

answers:

1
??? 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.

+6  A: 

Any Nullable<T>.

Check Gravell's exemple to strange corner cases in C#

Dynami Le Savard
An even more interesting example is the `MyFunnyType` on the same answer.
Marc Gravell