This keeps me wondering why Guid in .NET does not have IsNullOrEmpty()
method (where empty means all zeros)
I need this at several places in my ASP.NET
As others have pointed out, the premise of the question isn't all there. C# Guid
is not nullable. However, Guid?
is. A clean way of checking if a Guid?
is null
or Guid.Empty
is by check if the result of GetValueOrDefault()
is Guid.Empty
. E.g.,
Guid? id;
// some logic sets id
if (Guid.Empty.Equals(guid.GetValueOrDefault()))
{
// Do something
}