C# Guid ParseExact
Description
Guid ParseExact
converts the string representation
of a GUID to the equivalent Guid structure, provided that the string is in
the specified format.
Syntax
Guid.ParseExact
has the following syntax.
public static Guid ParseExact(
string input,
string format
)
Parameters
Guid.ParseExact
has the following parameters.
input
- The GUID to convert.format
- One of the following specifiers that indicates the exact format to use when interpreting input: "N", "D", "B", "P", or "X".
Returns
Guid.ParseExact
method returns A structure that contains the value that was parsed.
Example
The following example calls the ToString(String) method with each of the supported format specifiers to generate an array of strings that represent a single GUID.
//ww w . jav a2 s. com
using System;
public class Example
{
public static void Main()
{
string[] formats = { "N", "D", "B", "P", "X" };
Guid guid = Guid.NewGuid();
string[] stringGuids = new string[formats.Length];
for (int ctr = 0; ctr < formats.Length; ctr++)
stringGuids[ctr] = guid.ToString(formats[ctr]);
// Parse the strings in the array using the "B" format specifier.
foreach (var stringGuid in stringGuids) {
Guid newGuid = Guid.ParseExact(stringGuid, "B");
Console.WriteLine("Successfully parsed {0}", stringGuid);
}
}
}
The code above generates the following result.