Guid.Parse Method (String)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Converts the string representation of a GUID to the equivalent Guid structure.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)

public static Guid Parse(
	string input


Type: System.String

The string to convert.

Return Value

Type: System.Guid

A structure that contains the value that was parsed.

Exception Condition

input is null.


input is not in a recognized format.

The Parse method trims any leading or trailing white space from input and converts the string representation of a GUID to a Guid value. This method can convert strings in any of the five formats produced by the ToString(String) and ToString(String, IFormatProvider) methods, as shown in the following table.





32 digits



32 digits separated by hyphens



32 digits separated by hyphens, enclosed in braces



32 digits separated by hyphens, enclosed in parentheses



Four hexadecimal values enclosed in braces, where the fourth value is a subset of eight hexadecimal values that is also enclosed in braces


The method throws a FormatException if it is unable to successfully parse the string. Here are some of the reasons why this might occur include:

  • input contains characters that are not part of the hexadecimal character set.

  • input has too many or too few numeric characters.

  • input has too many or too few of the non-numeric characters appropriate for a particular format.

  • input is not in one of the formats recognized by the ToString method and listed in the previous table.

Use the TryParse method to catch any unsuccessful parse operations without having to handle an exception.

The following example creates a new GUID, converts it to three separate string representations by calling the ToString(String) method with the "B", "D", and "X" format specifiers, and then calls the Parse method to convert the strings back to Guid values.

using System;

public class Example
   public static void Main()
      Guid originalGuid = Guid.NewGuid();
      // Create an array of string representations of the GUID.
      string[] stringGuids = { originalGuid.ToString("B"),
                               originalGuid.ToString("X") };

      // Parse each string representation.
      foreach (var stringGuid in stringGuids) {
         try {     
            Guid newGuid = Guid.Parse(stringGuid);
            Console.WriteLine("Converted {0} to a Guid", stringGuid);
         catch (ArgumentNullException) {
            Console.WriteLine("The string to be parsed is null.");   
         catch (FormatException) {
            Console.WriteLine("Bad format: {0}", stringGuid);
// The example displays the following output:
//    Converted {81a130d2-502f-4cf1-a376-63edeb000e9f} to a Guid
//    Converted 81a130d2-502f-4cf1-a376-63edeb000e9f to a Guid
//    Converted {0x81a130d2,0x502f,0x4cf1,{0xa3,0x76,0x63,0xed,0xeb,0x00,0x0e,0x9f}} to a Guid

Universal Windows Platform
Available since 8
.NET Framework
Available since 4.0
Portable Class Library
Supported in: portable .NET platforms
Available since 4.0
Windows Phone Silverlight
Available since 7.1
Windows Phone
Available since 8.1
Return to top