Why are there dashes in a .NET GUID?

后端 未结 13 847
傲寒
傲寒 2020-12-03 00:11

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-859

相关标签:
13条回答
  • 2020-12-03 01:03

    It's just a convenience.

    http://en.wikipedia.org/wiki/GUID

    0 讨论(0)
  • 2020-12-03 01:03

    That's just for convenience. GUID consists of 16 bytes which makes up 32 characters in hex text representation. Without hyphens GUIDs are harder to perceive by humans and harder to be recognized as GUIDs and not some random nature 16-byte numbers.

    0 讨论(0)
  • 2020-12-03 01:07

    You can get your guid in various formats.

    Assuming you're using c#:

    Guid guid = Guid.NewGuid();
    
    Console.WriteLine(guid.ToString("N"))
    

    63be6f7e4e564f0580229f958f492077

    Console.WriteLine(guid.ToString("D"))
    

    63be6f7e-4e56-4f05-8022-9f958f492077

    Console.WriteLine(guid.ToString("B"))
    

    {63be6f7e-4e56-4f05-8022-9f958f492077}

    Console.WriteLine(guid.ToString("P"))
    

    (63be6f7e-4e56-4f05-8022-9f958f492077)

    0 讨论(0)
  • 2020-12-03 01:07

    This is an example of chunking, just like phone numbers, credit card numbers, etc.

    Here is a good Wikipedia article about it.

    0 讨论(0)
  • 2020-12-03 01:12

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

    0 讨论(0)
  • 2020-12-03 01:13

    The hyphens are used to separate each number

    E93416C5-9377-4A1D-8390-7E57D439C9E7

    Hex digits  Description
    8           Data1
    4           Data2
    4           Data3
    4           Initial two bytes from Data4
    12          Remaining six bytes from Data4
    
    0 讨论(0)
提交回复
热议问题