Export (0) Print
Expand All

Boolean.Parse Method

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

[Visual Basic]
Public Shared Function Parse( _
   ByVal value As String _
) As Boolean
[C#]
public static bool Parse(
 string value
);
[C++]
public: static bool Parse(
 String* value
);
[JScript]
public static function Parse(
   value : String
) : Boolean;

Parameters

value
A string containing the value to convert.

Return Value

true if value is equivalent to TrueString; otherwise, false.

Exceptions

Exception Type Condition
ArgumentNullException value is a null reference (Nothing in Visual Basic).
FormatException value is not equivalent to TrueString or FalseString.

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.

Example

The following code sample illustrates the use of Parse in the context of Boolean:

[Visual Basic] 
Dim val As Boolean
Dim input As String

input = Boolean.TrueString
val = Boolean.Parse(input)
Console.WriteLine("{0} parsed as {1}", input, val)

[C#] 
bool val;
string input;

input = bool.TrueString;
val = bool.Parse(input);
Console.WriteLine("{0} parsed as {1}", input, val);

[C++] 
Boolean val;
String* input;

input = Boolean::TrueString;
val = Boolean::Parse(input);
Console::WriteLine("{0} parsed as {1}", input, __box(val));

[JScript] 
var val : Boolean;
var input : String;

input = Boolean.TrueString;
val = Boolean.Parse(input);
Console.WriteLine("{0} parsed as {1}", input, val);

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

Boolean Structure | Boolean Members | System Namespace | ArgumentNullException | FormatException | String | TrueString | FalseString

Show:
© 2014 Microsoft