Export (0) Print
Expand All

Guid.ToString Method (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.

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

abstract ToString : 
        format:string * 
        provider:IFormatProvider -> string  
override ToString : 
        format:string * 
        provider:IFormatProvider -> string

Parameters

format
Type: System.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 a null reference (Nothing in Visual Basic) or an empty string (""), "D" is used.

provider
Type: System.IFormatProvider

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

Return Value

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

Implements

IFormattable.ToString(String, IFormatProvider)

ExceptionCondition
FormatException

The value of format is not a null reference (Nothing in Visual Basic), an empty string (""), "N", "D", "B", "P", or "X".

The provider parameter is reserved for future use and does not contribute to the execution of this method. You can pass a null reference (Nothing in Visual Basic) 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.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

.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