Getting the string representation of a Guid

suggest change

A string representation of a Guid can be obtained by using the built in ToString method

string myGuidString = myGuid.ToString();

Depending on your needs you can also format the Guid, by adding a format type argument to the ToString call.

var guid = new Guid("7febf16f-651b-43b0-a5e3-0da8da49e90d");

// None          "7febf16f651b43b0a5e30da8da49e90d"
Console.WriteLine(guid.ToString("N"));

// Hyphens       "7febf16f-651b-43b0-a5e3-0da8da49e90d"
Console.WriteLine(guid.ToString("D"));

// Braces        "{7febf16f-651b-43b0-a5e3-0da8da49e90d}"
Console.WriteLine(guid.ToString("B"));

// Parentheses   "(7febf16f-651b-43b0-a5e3-0da8da49e90d)"
Console.WriteLine(guid.ToString("P"));

// Hex           "{0x7febf16f,0x651b,0x43b0{0xa5,0xe3,0x0d,0xa8,0xda,0x49,0xe9,0x0d}}"
Console.WriteLine(guid.ToString("X"));

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents