Questions about GUID's: Are they always fixed in length, and is the middle number always 4?

前端 未结 3 2308
醉酒成梦
醉酒成梦 2021-02-19 18:55

I just generated a few million GUID\'s turned them into a String and got the length... it was always the same. Can I rely on this fixed length of the GUID when converting to St

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-19 19:50

    From the documentation on Guid.ToString (with no parameters):

    The value of this Guid, formatted as follows: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx where the value of the GUID is represented as a series of lowercase hexadecimal digits in groups of 8, 4, 4, 4, and 12 digits and separated by hyphens. An example of a return value is "382c74c3-721d-4f34-80e5-57657b6cbc27".

    So the answer is "yes", it will always be the same length.

    As for the 4, it is a version number (according to http://en.wikipedia.org/wiki/Uuid). Every GUID that you generate with that algorithm will have a 4 in that position, but older GUIDs will have a 1, 2, or 3. Future ones might have a 5 or something higher.

提交回复
热议问题