Boolean.ToString Method

Definition

Converts the value of this instance to its equivalent string representation (either "True" or "False").

Overloads

ToString(IFormatProvider)

Converts the value of this instance to its equivalent string representation (either "True" or "False").

ToString()

Converts the value of this instance to its equivalent string representation (either "True" or "False").

ToString(IFormatProvider)

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

Converts the value of this instance to its equivalent string representation (either "True" or "False").

C#
public string ToString (IFormatProvider? provider);
C#
public string ToString (IFormatProvider provider);

Parameters

provider
IFormatProvider

(Reserved) An IFormatProvider object.

Returns

TrueString if the value of this instance is true, or FalseString if the value of this instance is false.

Implements

Remarks

The provider parameter is reserved. It does not participate in the execution of this method. This means that the Boolean.ToString(IFormatProvider) method, unlike most methods with a provider parameter, does not reflect culture-specific settings.

This method returns the constants "True" or "False". Note that XML is case-sensitive, and that the XML specification recognizes "true" and "false" as the valid set of Boolean values. 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.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

ToString()

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

Converts the value of this instance to its equivalent string representation (either "True" or "False").

C#
public override string ToString ();

Returns

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

Examples

The following example illustrates the ToString method.

C#
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

Remarks

This method returns the constants "True" or "False".

Note that XML is case-sensitive, and that the XML specification recognizes "true" and "false" as the valid set of Boolean values. 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.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0