C# Guid ToByteArray
Description
Guid ToByteArray
returns a 16-element byte array that
contains the value of this instance.
Syntax
Guid.ToByteArray
has the following syntax.
public byte[] ToByteArray()
Returns
Guid.ToByteArray
method returns
Example
The following example calls the NewGuid method to create a Guid value, and then calls the ToByteArray method to represent the Guid value as a byte array.
//from w w w . j a v a2 s.c o m
using System;
public class Example
{
public static void Main()
{
Guid guid = Guid.NewGuid();
Console.WriteLine("Guid: {0}", guid);
Byte[] bytes = guid.ToByteArray();
foreach (var byt in bytes){
Console.Write("{0:X2} ", byt);
}
Guid guid2 = new Guid(bytes);
Console.WriteLine("Guid: {0} (Same as First Guid: {1})", guid2, guid2.Equals(guid));
}
}
The code above generates the following result.