DEV Community

loading...

Discussion on: 5 things you didn't know about Guid in C#

Collapse
elasticrash profile image
Stefanos Kouroupis

I am going to add a small detail, that hopefully will prevent headaches for people that work with Guids and ByteArrays.

Careful when you use Guid.ToByteArray the order of bytes is different from the string representation of the string value. Specifically if you want to create one with the same order you need to do the following (simplified)

        public static byte[] GenerateByteArray(byte[] g)
        {
            return new[]
                {g[3], g[2], g[1], g[0], g[5], g[4], g[7], g[6], g[8], g[9], g[10], g[11], g[12], g[13], g[14], g[15]};
        }