Guid.ToString Guid.ToString Guid.ToString Guid.ToString Method

Definition

Returns a string representation of the value of this instance of the Guid structure.

Overloads

ToString() ToString() ToString() ToString()

Returns a string representation of the value of this instance in registry format.

ToString(String) ToString(String) ToString(String) ToString(String)

Returns a string representation of the value of this Guid instance, according to the provided format specifier.

ToString(String, IFormatProvider) ToString(String, IFormatProvider) ToString(String, IFormatProvider) ToString(String, IFormatProvider)

Returns a string representation of the value of this instance of the Guid class, according to the provided format specifier and culture-specific format information.

ToString() ToString() ToString() ToString()

Returns a string representation of the value of this instance in registry format.

public:
 override System::String ^ ToString();
public override string ToString ();
override this.ToString : unit -> string
Public Overrides Function ToString () As String

Returns

The value of this Guid, formatted by using the "D" format specifier as follows:

xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

where the value of the GUID is represented as a series of lowercase hexadecimal digits in groups of 8, 4, 4, 4, and 12 digits and separated by hyphens. An example of a return value is "382c74c3-721d-4f34-80e5-57657b6cbc27". To convert the hexadecimal digits from a through f to uppercase, call the ToUpper() method on the returned string.

Remarks

This method provides a default GUID format that is sufficient for typical use; however, other versions of this method that take a format parameter provide a few common format variations.

ToString(String) ToString(String) ToString(String) ToString(String)

Returns a string representation of the value of this Guid instance, according to the provided format specifier.

public:
 System::String ^ ToString(System::String ^ format);
public string ToString (string format);
override this.ToString : string -> string
Public Function ToString (format As String) As String

Parameters

format
String String String String

A single format specifier that indicates how to format the value of this Guid. The format parameter can be "N", "D", "B", "P", or "X". If format is null or an empty string (""), "D" is used.

Returns

The value of this Guid, represented as a series of lowercase hexadecimal digits in the specified format.

Exceptions

The value of format is not null, an empty string (""), "N", "D", "B", "P", or "X".

Remarks

The following table shows the accepted format specifiers for the format parameter. "0" represents a digit; hyphens ("-"), braces ("{", "}"), and parentheses ("(", ")") appear as shown.

Specifier Format of return value
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 hexadecimal digits a through f are lowercase in the returned string. To convert them to uppercase, call the String.ToUpper method on the returned string.

ToString(String, IFormatProvider) ToString(String, IFormatProvider) ToString(String, IFormatProvider) ToString(String, IFormatProvider)

Returns a string representation of the value of this instance of the Guid class, according to the provided format specifier and culture-specific format information.

public:
 virtual System::String ^ ToString(System::String ^ format, IFormatProvider ^ provider);
public string ToString (string format, IFormatProvider provider);
override this.ToString : string * IFormatProvider -> string
Public Function ToString (format As String, provider As IFormatProvider) As String

Parameters

format
String String String String

A single format specifier that indicates how to format the value of this Guid. The format parameter can be "N", "D", "B", "P", or "X". If format is null or an empty string (""), "D" is used.

provider
IFormatProvider IFormatProvider IFormatProvider IFormatProvider

(Reserved) An object that supplies culture-specific formatting information.

Returns

The value of this Guid, represented as a series of lowercase hexadecimal digits in the specified format.

Implements

Exceptions

The value of format is not null, an empty string (""), "N", "D", "B", "P", or "X".

Remarks

The provider parameter is reserved for future use and does not contribute to the execution of this method. You can pass null in the method call.

The following table shows the accepted format specifiers for the format parameter. "0" represents a digit; hyphens ("-"), braces ("{", "}"), and parentheses ("(", ")") appear as shown.

Specifier Format of return value
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 hexadecimal digits a through f are lowercase in the returned string. To convert them to uppercase, call the String.ToUpper method on the returned string.

Because the provider parameter is ignored, you cannot use it to provide a custom formatting solution. To represent a Guid value as a string in a format that isn't supported by the standard GUID format strings, call the String.Format(IFormatProvider, String, Object[]) method with a provider object that implements both the ICustomFormatter and IFormatProvider interfaces. For more information, see the "Custom Formatting with ICustomFormatter" section in the Formatting Types article.

Applies to