I have some generic method
T SomeMethod(Func<T> func){
T result = func();
if (result != null)
{ //.....}
}
It works good if T is class. But what should I do if T is struct? How can I check if result == default(T) in case if T is struct?
P.S. I don’t want to use the constraint where T: class or Nullable types.
If
Tis compiled to be astructthen the comparison withnullwill always evaluate tofalse. This is covered in section 7.9.6 of the C# language spec