Why are there dashes in a .NET GUID?

Viewed 12604

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

13 Answers

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.

Just about every visual represenation of a guid that I've seen uses the dashed format. It's much easier on the eyes.

The Guid class of .NET recognizes a bunch of different formats: dashes as separators, no separators, brackets as delimiters, parenthesis as delimiters, no delimiters, etc

Related