Boolean.ToString 方法

定義

將這個執行個體的值轉換為它的對等字串表示 ("True" 或 "False")。

多載

ToString(IFormatProvider)

將這個執行個體的值轉換為它的對等字串表示 ("True" 或 "False")。

ToString()

將這個執行個體的值轉換為它的對等字串表示 ("True" 或 "False")。

ToString(IFormatProvider)

將這個執行個體的值轉換為它的對等字串表示 ("True" 或 "False")。

public:
 virtual System::String ^ ToString(IFormatProvider ^ provider);
public 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 物件。

傳回

如果這個執行個體的值是 TrueString,則為 true;如果這個執行個體的值是 FalseString 則為 false

實作

備註

參數 provider 是保留的。 它不會參與這個方法的執行。 這表示 Boolean.ToString(IFormatProvider) 方法與大部分具有 provider 參數的方法不同,不會反映特定文化特性的設定。

這個方法會傳回常數 「True」 或 「False」。 請注意,XML 區分大小寫,而且 XML 規格會將 「true」 和 「false」 辨識為有效的布林值集。 String如果方法所 ToString(IFormatProvider) 傳回的物件要寫入 XML 檔案,則應該先呼叫其 String.ToLowerInvariant 方法,將其轉換成小寫。

適用於

ToString()

將這個執行個體的值轉換為它的對等字串表示 ("True" 或 "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 屬性值)。

範例

下列範例說明 ToString 方法。

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
let raining = false
let busLate = true

printfn $"raining.ToString() returns {raining}" 
printfn $"busLate.ToString() returns {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」。

請注意,XML 區分大小寫,而且 XML 規格會將 「true」 和 「false」 辨識為有效的布林值集。 如果方法所傳回的 ToString() 字串要寫入 XML 檔案,則應該先呼叫其 String.ToLowerInvariant 方法,將其轉換成小寫。

適用於