CKTIS / C#
Boolean.Parse — converting text to a Boolean value
Boolean.Parse converts text representing True or False to bool. It ignores letter case and leading or trailing whitespace and NUL characters. Invalid input throws an exception rather than returning false.
Version: .NET 10; repository net10.0 and LangVersion=preview; feature versions require per-entry verification
Syntax
public static bool Parse(string value);
public static bool Parse(ReadOnlySpan<char> value);Boolean.Parse is a static method on System.Boolean; bool.Parse names the same method. .NET 10 provides overloads accepting string and ReadOnlySpan<char>. Both return bool.
Both overloads accept text that matches TrueString ("True") or FalseString ("False") without regard to letter case. They ignore leading and trailing whitespace and NUL characters (U+0000). NUL is not a whitespace character. Thus, " tRuE " produces true. The strings "1", "0", "yes", and empty text are not valid values.
Invalid formatting causes FormatException, while passing null to the string overload causes ArgumentNullException. A result of false means a successfully parsed value, not an error. When invalid input is expected, choose Boolean.TryParse: its return value indicates success, and its out parameter contains the parsed value.
Examples
using System;
Console.WriteLine(Boolean.Parse(" tRuE "));
Console.WriteLine(bool.Parse("FALSE".AsSpan()));
try
{
Boolean.Parse("1");
}
catch (FormatException)
{
Console.WriteLine("FormatException");
}Result
True False FormatException
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.