C# - 为什么 System.Guid 翻转字节数组中的字节?

标签 c# guid

当在 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/

相关文章:

c# - 对类类型操作数使用 == 运算符

c# - 将文本添加到图像文件

javascript - 使用 AngularJS 的 $http.get() 处理 64 位数字

c++ - 写入 .ini 文件 - SimpleIni SetValue 没有做任何事情,尽管看起来成功了

mysql - 我应该如何在 MySQL 表中存储 GUID?

c# - "Bad key"带有可导出私钥的证书异常

c# - 如何在没有任何身份验证的情况下调用 WCF 服务?

c# - 在 dataGridView 中移动索引

sql-server - SQL SERVER - INT Vs GUID - 我们应该使用什么

c# - Fluent NHibernate 映射 GUID 类型属性 NOT Identity