Boolean.Parse Method

Definition

Overloads

Parse(ReadOnlySpan<Char>)

Converts the specified span representation of a logical value to its Boolean equivalent.

Parse(String)

Converts the specified string representation of a logical value to its Boolean equivalent.

Parse(ReadOnlySpan<Char>)

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

Converts the specified span representation of a logical value to its Boolean equivalent.

C#
public static bool Parse(ReadOnlySpan<char> value);

Parameters

value
ReadOnlySpan<Char>

A span containing the characters representing the value to convert.

Returns

true if value is equivalent to TrueString; false if value is equivalent to FalseString.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Standard 2.1

Parse(String)

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

Converts the specified string representation of a logical value to its Boolean equivalent.

C#
public static bool Parse(string value);

Parameters

value
String

A string containing the value to convert.

Returns

true if value is equivalent to TrueString; false if value is equivalent to FalseString.

Exceptions

value is null.

value is not equivalent to TrueString or FalseString.

Examples

The following code example illustrates the use of Parse method.

C#
bool val;
string input;

input = bool.TrueString;
val = bool.Parse(input);
Console.WriteLine("'{0}' parsed as {1}", input, val);
// The example displays the following output:
//       'True' parsed as True

Remarks

The value parameter, optionally preceded or trailed by white space, must contain either TrueString or FalseString; otherwise, an exception is thrown. The comparison is case-insensitive.

See also

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