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

定义

返回 Guid 结构的此实例值的字符串表示形式。Returns a string representation of the value of this instance of the Guid structure.

重载

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)

根据所提供的格式说明符,返回此 Guid 实例值的字符串表示形式。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)

根据所提供的格式说明符和区域性特定的格式信息,返回 Guid 类的此实例值的字符串表示形式。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

返回

Guid的值,格式化通过使用“D”格式说明符如下所示:The value of this Guid, formatted by using the "D" format specifier as follows: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

其中 GUID 的值表示为一系列小写的十六进制位,这些十六进制位分别以 8 个、4 个、4 个、4 个和 12 个位为一组并由连字符分隔开。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. 例如,返回值可以是“382c74c3-721d-4f34-80e5-57657b6cbc27”。An example of a return value is "382c74c3-721d-4f34-80e5-57657b6cbc27". 若要将从 a 到 f 的十六进制数转换为大写,请对返回的字符串调用 ToUpper() 方法。To convert the hexadecimal digits from a through f to uppercase, call the ToUpper() method on the returned string.

注解

此方法提供的默认 GUID 格式足以满足典型用途;但是,此方法的其他版本采用 format 参数会提供一些常见格式变化形式。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)

根据所提供的格式说明符,返回此 Guid 实例值的字符串表示形式。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

参数

format
String String String String

一个单格式说明符,它指示如何格式化此 Guid 的值。A single format specifier that indicates how to format the value of this Guid. format 参数可以是“N”、“D”、“B”、“P”或“X”。The format parameter can be "N", "D", "B", "P", or "X". 如果 formatnull 或空字符串 (""),则使用“D”。If format is null or an empty string (""), "D" is used.

返回

Guid 的值,用一系列指定格式的小写十六进制位表示。The value of this Guid, represented as a series of lowercase hexadecimal digits in the specified format.

异常

format 的值不是 null、空字符串 ("")、“N”、“D”、“B”、“P”或“X”。The value of format is not null, an empty string (""), "N", "D", "B", "P", or "X".

注解

下表显示 @no__t 参数的已接受格式说明符。The following table shows the accepted format specifiers for the format parameter. "0" 表示一个数字;连字符("-")、大括号("{"、"}")和括号("(",")")如图所示。"0" represents a digit; hyphens ("-"), braces ("{", "}"), and parentheses ("(", ")") appear as shown.

说明符Specifier 返回值的格式Format of return value
N 32位数:32 digits:

0000000000000000000000000000000000000000000000000000000000000000
D 32的数字,由连字符分隔:32 digits separated by hyphens:

00000000-0000-0000-0000-00000000000000000000-0000-0000-0000-000000000000
B 32位,用连字符隔开,括在大括号中:32 digits separated by hyphens, enclosed in braces:

{00000000-0000-0000-0000-000000000000}
P 32位,用连字符隔开,括在括号中:32 digits separated by hyphens, enclosed in parentheses:

(00000000-0000-0000-0000-000000000000)(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}}{0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}

在返回的字符串中,从 a 到 f 的十六进制数字是小写的。The hexadecimal digits a through f are lowercase in the returned string. 若要将其转换为大写,请对返回的字符串调用 String.ToUpper 方法。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)

根据所提供的格式说明符和区域性特定的格式信息,返回 Guid 类的此实例值的字符串表示形式。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

参数

format
String String String String

一个单格式说明符,它指示如何格式化此 Guid 的值。A single format specifier that indicates how to format the value of this Guid. format 参数可以是“N”、“D”、“B”、“P”或“X”。The format parameter can be "N", "D", "B", "P", or "X". 如果 formatnull 或空字符串 (""),则使用“D”。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.

返回

Guid 的值,用一系列指定格式的小写十六进制位表示。The value of this Guid, represented as a series of lowercase hexadecimal digits in the specified format.

实现

异常

format 的值不是 null、空字符串 ("")、“N”、“D”、“B”、“P”或“X”。The value of format is not null, an empty string (""), "N", "D", "B", "P", or "X".

注解

@No__t 的参数保留供将来使用,并且不会影响此方法的执行。The provider parameter is reserved for future use and does not contribute to the execution of this method. 可以在方法调用中传递 nullYou can pass null in the method call.

下表显示 @no__t 参数的已接受格式说明符。The following table shows the accepted format specifiers for the format parameter. "0" 表示一个数字;连字符("-")、大括号("{"、"}")和括号("(",")")如图所示。"0" represents a digit; hyphens ("-"), braces ("{", "}"), and parentheses ("(", ")") appear as shown.

说明符Specifier 返回值的格式Format of return value
N 32位数:32 digits:

0000000000000000000000000000000000000000000000000000000000000000
D 32的数字,由连字符分隔:32 digits separated by hyphens:

00000000-0000-0000-0000-00000000000000000000-0000-0000-0000-000000000000
B 32位,用连字符隔开,括在大括号中:32 digits separated by hyphens, enclosed in braces:

{00000000-0000-0000-0000-000000000000}
P 32位,用连字符隔开,括在括号中:32 digits separated by hyphens, enclosed in parentheses:

(00000000-0000-0000-0000-000000000000)(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}}{0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}

在返回的字符串中,从 a 到 f 的十六进制数字是小写的。The hexadecimal digits a through f are lowercase in the returned string. 若要将其转换为大写,请对返回的字符串调用 String.ToUpper 方法。To convert them to uppercase, call the String.ToUpper method on the returned string.

由于 @no__t 的参数将被忽略,因此不能使用它来提供自定义格式设置解决方案。Because the provider parameter is ignored, you cannot use it to provide a custom formatting solution. 若要将 @no__t 0 值表示为不受标准 GUID 格式字符串支持的格式的字符串,请使用同时实现 @no__t 3 和 @no__t 4 的 provider 对象调用 String.Format(IFormatProvider, String, Object[]) 方法。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. 有关详细信息,请参阅格式设置一文中的 "带 ICustomFormatter 的自定义格式" 部分。For more information, see the "Custom Formatting with ICustomFormatter" section in the Formatting Types article.

适用于