Check if Nullable Guid is empty in c#

Saturnix picture Saturnix · Jul 17, 2013 · Viewed 99.9k times · Source

Quoting from an answer from this question.

Guid is a value type, so a variable of type Guid can't be null to start with.

What then if I see this?

public Nullable<System.Guid> SomeProperty { get; set; }

how should I check if this is null? Like this?

(SomeProperty == null)

or like this?

(SomeProperty == Guid.Empty)

Answer

Sir l33tname picture Sir l33tname · Jul 17, 2013

If you want be sure you need to check both

SomeProperty == null || SomeProperty == Guid.Empty

Because it can be null 'Nullable' and it can be an empty GUID something like this {00000000-0000-0000-0000-000000000000}