In a C# ASP.NET website or application, sometimes we need to check if a GUID being passed is empty or not.

Sometimes, we also need to generate an empty GUID for different use cases.

In C#, we can easily create an empty or default GUID using the GUID static class that the system namespace provides us.

We can also compare a GUID value to check whether it's an empty GUID.

An Empty GUID is also known as a default GUID because the default value for a GUID is an empty GUID.

 

 

 

 

Create An Empty GUID In C# Using Guid.NewGuid() (Default GUID)

In C#, we can use the struct Guid which is available in the System namespace and create a new empty or default GUID.

We get a read only instance of the GUID structure whose value is all zeros. This is known as an empty GUID.

The syntax to create an empty or default GUID is:

Console.WriteLine(Guid.Empty); // Result: 00000000-0000-0000-0000-000000000000

 

 

Check Empty GUID In C#

Sometimes, as a validation step, we might have to check the value of a GUID to see if it's not a default or empty GUID value.

We can use the Guid.Empty property to check if value of GUID is empty or default.

var incomingGuid = Guid.NewGuid(); if (incomingGuid != Guid.Empty) { Console.WriteLine("GUID is not empty"); } // Result: GUID is not empty