No, it will not return null . But here's what you need to know!
static void WhatAmI<T>() where T : new() { T t = new T(); Console.WriteLine("t.ToString(): {0}", t.ToString()); Console.WriteLine("t.GetHashCode(): {0}", t.GetHashCode()); Console.WriteLine("t.Equals(t): {0}", t.Equals(t)); Console.WriteLine("t.GetType(): {0}", t.GetType()); }
Here's the output for some T :
t.ToString(): t.GetHashCode(): 0 t.Equals(t): True Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
What is T ? Answer: any Nullable<U> .
(Original credit concept for Mark Gravell.)
jason
source share