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".

備註

下表顯示format參數接受的格式規範。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".

備註

provider參數保留供未來使用,而且不會參與此方法的執行。The provider parameter is reserved for future use and does not contribute to the execution of this method. 您可以傳入null方法呼叫。You can pass null in the method call.

下表顯示format參數接受的格式規範。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.

因為已忽略參數,所以您無法使用它來提供自訂格式解決方案。 providerBecause the provider parameter is ignored, you cannot use it to provide a custom formatting solution. 若要以Guid標準 GUID 格式字串不支援的格式將值表示為字串,請使用同時ICustomFormatter執行providerString.Format(IFormatProvider, String, Object[]) IFormatProvider介面的物件來呼叫方法。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.

適用於