Export (0) Print
Expand All

Guid::Parse Method

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
)

Parameters

input
Type: System::String

The string to convert.

Return Value

Type: System::Guid
A structure that contains the value that was parsed.

ExceptionCondition
ArgumentNullException

input is nullptr.

FormatException

input is not in a recognized format.

The Parse method 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.

Specifier

Description

Format

N

32 digits

00000000000000000000000000000000

D

32 digits separated by hyphens

00000000-0000-0000-0000-000000000000

B

32 digits separated by hyphens, enclosed in braces

{00000000-0000-0000-0000-000000000000}

P

32 digits separated by hyphens, enclosed in parentheses

(00000000-0000-0000-0000-000000000000)

X

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

{0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}

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.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4

.NET Framework Client Profile

Supported in: 4

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft