Getting the string representation of a Guid
suggest changeA 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"));
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents