Mohanapriya R Mohanapriya R
Updated date Jul 15, 2024
In this blog, we will learn how to convert GUIDs to readable strings in C#.
  • 2.5k
  • 0
  • 0

Converting GUIDs to Strings in C#:

A GUID is a 128-bit identifier, typically displayed as a 32-character hexadecimal number, often separated by hyphens. While GUIDs are effective for unique identification, they are not as human-readable as strings. 

In C#, the ToString method of the Guid structure is used to convert a GUID to its string representation. 

using System;

class Program
{
    static void Main()
    {
        // Generating a new GUID
        Guid myGuid = Guid.NewGuid();
        
        // Converting GUID to string
        string guidString = myGuid.ToString();
        
        // Displaying the original GUID and the converted string
        Console.WriteLine("Original GUID: " + myGuid);
        Console.WriteLine("Converted String: " + guidString);
    }
}

In the above example, a new GUID (myGuid) is generated using Guid.NewGuid(). The ToString method is then applied to convert the GUID to its string (guidString). 

Output:

Original GUID: f47ac10b-58cc-4372-a567-0e02b2c3d479
Converted String: f47ac10b-58cc-4372-a567-0e02b2c3d479

 

Comments (0)

There are no comments. Be the first to comment!!!