Guid.IFormattable.ToString(String, IFormatProvider) 方法

定義

依據提供的格式指定名稱及文化特性 (Culture) 專用格式資訊,傳回此執行個體之值的字串表示。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

參數

format
String

單一格式的規範,指示如何格式化 Guid 的值。A single format specifier that indicates how to format the value of the Guid. format 參數可能是 "N"、"D"、"B"、"P" 或 "X"。The format parameter can be "N", "D", "B", "P", or "X". 如果 format 為 Null 或為空白字串 (""),則會使用 "D"。If format is null or an empty string (""), "D" is used.

provider
IFormatProvider

(保留) 物件,提供特定文化特性格式資訊。(Reserved) An object that supplies culture-specific formatting information.

傳回

String

這個 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 (""), or one of the following single format specifiers:"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. 您可以在方法呼叫中傳遞 nullYou 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.

因為會忽略 provider 參數,所以您無法使用它來提供自訂格式解決方案。Because the provider parameter is ignored, you cannot use it to provide a custom formatting solution. 若要以標準 GUID 格式字串不支援的格式將 Guid 值表示為字串,請使用同時執行 ICustomFormatterIFormatProvider 介面的 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.

適用於