当在 C# 即时窗口中输入以下代码时,它会产生一些异常结果,我只能假设这是因为在内部,System.Guid
翻转了某些字节:
当使用从 0 到 15 的有序字节数组时
new Guid(new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15})
[03020100-0504-0706-0809-0a0b0c0d0e0f]
当使用值为 0 到 15 的非有序字节数组时
new Guid(new byte[] {3, 2, 1, 0, 5, 4, 7, 6, 8, 9, 10, 11, 12, 13, 14, 15})
[00010203-0405-0607-0809-0a0b0c0d0e0f]
为什么前 3 组翻转了?
最佳答案
发现于 Wikipedia关于 UUID。
Other systems, notably Microsoft's marshalling of UUIDs in their COM/OLE libraries, use a mixed-endian format, whereby the first three components of the UUID are little-endian, and the last two are big-endian.
For example, 00112233-4455-6677-8899-aabbccddeeff is encoded as the bytes 33 22 11 00 55 44 77 66 88 99 aa bb cc dd ee ff
关于C# - 为什么 System.Guid 翻转字节数组中的字节?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45671415/