Search code examples
.netguiduuid

Why are there dashes in a .NET GUID?


Why are there dashes in a .NET GUID? Are there dashes in most implementations of a GUID, or is it just a Microsoft thing?

Signed,

741ecf77-9c92-4435-8e6b-85975bd13452


Solution

  • Technically, there are no "dashes" in a GUID. A GUID is a 128-bit value which is usually stored in the following manner (using C# here to represent the structure):

    public struct Guid
    {
      public ulong Data1;
      public ushort Data2;
      public ushort Data3;
      public fixed byte Data4[8];
    }
    

    The dashes are in the string representation of a GUID.

    The dashes are optional and are not required in a string representation of a GUID.

    That said, there are historical reasons as to where the placement of the dashes are, related to how the GUIDs were generated, but that historical semantic no longer applies.