Comparison with default(T)
I was working on a generic class that I had limited to
where : class because I wanted to use null as valid return value. Well, then I needed to use the class on Guid, which is a value type. So I replaced all
return null with
return default(T). That was fine except for my Enumerator which used null to
yield break out of the iteration. Unfortunately
wasn't legal either. Then i thought, how about
which compiles just fine, but of course throws a
NullArgumentException, since I am after all looking for a null value.
After some digging I finally came across the solution:
and that did the trick.