Back to Home

C# GUID.Empty Explained — Empty, Default, and New Guid()

Guid.Empty is the zero-value GUID and is often used as a sentinel for “not assigned yet.” It is the clearest choice in most code when you want to indicate an unset identifier without using null.

Guid.Empty vs default(Guid) vs new Guid()

C# Example Code
Guid empty = Guid.Empty;
Guid defaultValue = default(Guid);
Guid created = new Guid();

Console.WriteLine(empty == defaultValue); // True
Console.WriteLine(empty == created);      // True

Use Guid.Empty when you want readable intent. default(Guid) is equivalent, but Guid.Empty makes the purpose obvious in reviews and guard clauses.

When to use it

C# Example Code
Guid customerId = Guid.Empty;

if (customerId == Guid.Empty)
{
    Console.WriteLine("Customer ID has not been assigned yet.");
}

Common pitfalls

  • Guid.Empty is not the same as null for a nullable Guid?.
  • Prefer Guid comparisons over string comparisons when possible.
  • If you need true null semantics in an API, prefer Guid? or a dedicated wrapper type.

FAQ

Is Guid.Empty the same as default(Guid)?

Yes. Both are all-zero GUIDs. Guid.Empty is more expressive.

Should I use Guid.Empty or null?

Use Guid.Empty when you want a value type to mean “unset.” Use Guid? when you need real null semantics.

Take It Further

The C# Player's Guide book cover

The community's favorite C# guide — teaches every concept you just read about with clarity.

The C# Player's Guide — 5th Edition · RB Whitaker

Get it on Amazon →

As an Amazon Associate I earn from qualifying purchases.