Boolean.Parse(String) Method

Definition

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

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.

Boolean val;
String^ input;
input = Boolean::TrueString;
val = Boolean::Parse( input );
Console::WriteLine(  "'{0}' parsed as {1}", input, val );
// The example displays the following output:
//       'True' parsed as True        
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        
Dim val As Boolean
Dim input As String

input = Boolean.TrueString
val = Boolean.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.

Applies to

See Also