I was thinking about GUIDs recently, which led me to try this code:
Guid guid = Guid.NewGuid(); Console.WriteLine(guid.ToString()); //prints 6d1dc8c8-cd83-45b2-915f-c759134b93aa Console.WriteLine(BitConverter.ToString(guid.ToByteArray())); //prints C8-C8-1D-6D-83-CD-B2-45-91-5F-C7-59-13-4B-93-AA bool same=guid.ToString()==BitConverter.ToString(guid.ToByteArray()); //false Console.WriteLine(same); You can see that all of the bytes are there, but half of them are in the wrong order when I use BitConverter.ToString. Why is this?
guid.ToByteArray()Returns a 16-element byte array that contains the value of this instance.