Converts the specified string representation of a logical value to its bool equivalent, or throws an exception if the string is not equal to the value of bool.TrueString or bool.FalseString.
true if value is equal to the value of the bool.TrueString field; false if value is equal to the value of the bool.FalseString field.
Type Reason ArgumentNullException value is a null reference. FormatException value is not equivalent to either bool.TrueString or bool.FalseString.
The value parameter, optionally preceded or trailed by white space, must contain a string that is equal to the value of either the bool.TrueString or bool.FalseString field; otherwise, a FormatException is thrown. The comparison is ordinal and case-insensitive.
You can call the bool.TryParse(string, Boolean@) method to parse a string without having to handle the FormatException exception that is thrown if the parsing operation fails.
The following example demonstrates the bool.Parse(string) method.
C# Example
using System; public class BoolParse { public static void Main() { Boolean b = Boolean.Parse(" true "); Console.WriteLine("\" true \" parses to \"{0}\".", b); } }
The output is
" true " parses to "True".