Guid.IFormattable.ToString(String, IFormatProvider) Method


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

 virtual System::String ^ System.IFormattable.ToString(System::String ^ format, IFormatProvider ^ provider) = IFormattable::ToString;
string IFormattable.ToString (string format, IFormatProvider provider);
abstract member System.IFormattable.ToString : string * IFormatProvider -> string
override this.System.IFormattable.ToString : string * IFormatProvider -> string
Function ToString (format As String, provider As IFormatProvider) As String Implements IFormattable.ToString



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


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


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



The value of format is not null, an empty string (""), or one of the following single format specifiers:"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 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:

D 32 digits separated by hyphens:

B 32 digits separated by hyphens, enclosed in braces:

P 32 digits separated by hyphens, enclosed in parentheses:

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


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