Boolean.ToString 方法

定義

將這個執行個體的值轉換為它的對等字串表示 ("True" 或 "False")。Converts the value of this instance to its equivalent string representation (either "True" or "False").

多載

ToString(IFormatProvider)

將這個執行個體的值轉換為它的對等字串表示 ("True" 或 "False")。Converts the value of this instance to its equivalent string representation (either "True" or "False").

ToString()

將這個執行個體的值轉換為它的對等字串表示 ("True" 或 "False")。Converts the value of this instance to its equivalent string representation (either "True" or "False").

ToString(IFormatProvider)

將這個執行個體的值轉換為它的對等字串表示 ("True" 或 "False")。Converts the value of this instance to its equivalent string representation (either "True" or "False").

public:
 virtual System::String ^ ToString(IFormatProvider ^ provider);
public string ToString (IFormatProvider provider);
override this.ToString : IFormatProvider -> string
Public Function ToString (provider As IFormatProvider) As String

參數

provider
IFormatProvider

(已保留) IFormatProvider 物件。(Reserved) An IFormatProvider object.

傳回

如果這個執行個體的值是 TrueString,則為 true;如果這個執行個體的值是 FalseString 則為 falseTrueString if the value of this instance is true, or FalseString if the value of this instance is false.

實作

備註

參數provider是保留的。The provider parameter is reserved. 它不會參與此方法的執行。It does not participate in the execution of this method. 這表示Boolean.ToString(IFormatProvider)方法與大多數provider具有參數的方法不同,並不會反映特定文化特性的設定。This means that the Boolean.ToString(IFormatProvider) method, unlike most methods with a provider parameter, does not reflect culture-specific settings.

這個方法會傳回常數 "True" 或 "False"。This method returns the constants "True" or "False". 請注意,XML 會區分大小寫,而且 XML 規格會將 "true" 和 "false" 辨識為一組有效的布林值。Note that XML is case-sensitive, and that the XML specification recognizes "true" and "false" as the valid set of Boolean values. 如果ToString(IFormatProvider)方法String所傳回的物件要寫入 XML 檔案,則應該先呼叫它String.ToLowerInvariant的方法,將它轉換成小寫。If the String object returned by the ToString(IFormatProvider) method is to be written to an XML file, its String.ToLowerInvariant method should be called first to convert it to lowercase.

ToString()

將這個執行個體的值轉換為它的對等字串表示 ("True" 或 "False")。Converts the value of this instance to its equivalent string representation (either "True" or "False").

public:
 override System::String ^ ToString();
public override string ToString ();
override this.ToString : unit -> string
Public Overrides Function ToString () As String

傳回

如果這個執行個體的值是 true,則為 "True" (TrueString 屬性值);如果這個執行個體的值是 false,則為 "False" (FalseString 屬性值)。"True" (the value of the TrueString property) if the value of this instance is true, or "False" (the value of the FalseString property) if the value of this instance is false.

範例

下列範例說明ToString方法。The following example illustrates the ToString method.

Boolean raining = false;
Boolean busLate = true;
Console::WriteLine(  "raining->ToString() returns {0}", raining.ToString() );
Console::WriteLine(  "busLate->ToString() returns {0}", busLate.ToString() );
// The example displays the following output:
//       raining.ToString() returns False
//       busLate.ToString() returns True
bool raining = false;
bool busLate = true;

Console.WriteLine("raining.ToString() returns {0}", raining);
Console.WriteLine("busLate.ToString() returns {0}", busLate);
// The example displays the following output:
//       raining.ToString() returns False
//       busLate.ToString() returns True
Dim raining As Boolean = False
Dim busLate As Boolean = True

Console.WriteLine("raining.ToString() returns {0}", raining)
Console.WriteLine("busLate.ToString() returns {0}", busLate)
' The example displays the following output:
'       raining.ToString() returns False
'       busLate.ToString() returns True

備註

這個方法會傳回常數 "True" 或 "False"。This method returns the constants "True" or "False".

請注意,XML 會區分大小寫,而且 XML 規格會將 "true" 和 "false" 辨識為一組有效的布林值。Note that XML is case-sensitive, and that the XML specification recognizes "true" and "false" as the valid set of Boolean values. 如果ToString()方法所傳回的字串要寫入至 XML 檔案,則應該先呼叫它String.ToLowerInvariant的方法,將它轉換成小寫。If the string returned by the ToString() method is to be written to an XML file, its String.ToLowerInvariant method should be called first to convert it to lowercase.

適用於