C# Guid Empty

Description

Guid Empty a read-only instance of the Guid structure whose value is all zeros.

Syntax

Guid.Empty has the following syntax.


public static readonly Guid Empty

Example

The following example uses the Equality operator to compare two GUID values with Guid.Empty to determine whether they consist exclusively of zeros.


using System;//  w  w w  .  j  a va 2 s.  c om

public class Example
{
   public static void Main()
   {
      // Create a GUID and determine whether it consists of all zeros.
      Guid guid1 = Guid.NewGuid();
      Console.WriteLine(guid1);
      Console.WriteLine("Empty: {0}\n", guid1 == Guid.Empty);

      // Create a GUID with all zeros and compare it to Empty.
      Byte[] bytes = new Byte[16];
      Guid guid2 = new Guid(bytes);
      Console.WriteLine(guid2);
      Console.WriteLine("Empty: {0}", guid2 == Guid.Empty);
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version