语言

Boolean.ToString 方法

定义

将此实例的值转换为其等效的字符串表示形式(“True”或“False”)。

重载

名称 说明
ToString(IFormatProvider)

将此实例的值转换为其等效的字符串表示形式(“True”或“False”)。

ToString()

将此实例的值转换为其等效的字符串表示形式(“True”或“False”)。

ToString(IFormatProvider)

Source:
Boolean.cs
Source:
Boolean.cs
Source:
Boolean.cs
Source:
Boolean.cs
Source:
Boolean.cs

将此实例的值转换为其等效的字符串表示形式(“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 。

返回

如果此实例的值为,或者此实例的值为 ,则为 。

实现

注解

保留 provider 参数。 它不参与此方法的执行。 这意味着该方法 Boolean.ToString(IFormatProvider) 与大多数具有 provider 参数的方法不同,不会反映区域性特定的设置。

此方法返回常量“True”或“False”。 请注意,XML 区分大小写,并且 XML 规范将“true”和“false”识别为布尔值的有效集。 String如果方法返回ToString(IFormatProvider)的对象要写入 XML 文件,则应首先调用其String.ToLowerInvariant方法以将其转换为小写。

适用于

ToString()

Source:
Boolean.cs
Source:
Boolean.cs
Source:
Boolean.cs
Source:
Boolean.cs
Source:
Boolean.cs

将此实例的值转换为其等效的字符串表示形式(“True”或“False”)。

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

返回

如果此实例的值为TrueString“True”(属性的值true),则为“False”(属性的值FalseString),如果此实例的值是false,则为“False”。

示例

下面的示例演示了该方法 ToString 。

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 方法以将其转换为小写。

适用于