Convert.ToBoolean Method (Object)
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Converts the value of a specified Object to an equivalent Boolean value.
Assembly: mscorlib (in mscorlib.dll)
Parameters
- value
- Type: System.Object
An Object that implements the IConvertible interface or Nothing.
Return Value
Type: System.Booleantrue or false, which reflects the value returned by invoking the IConvertible.ToBoolean method for the underlying type of value. If value is Nothing, the method returns false.
The following code sample illustrates the use of the ToBoolean method, converting a string value to a Boolean type.
Public Sub ConvertStringBoolean(ByVal stringVal As String) Dim boolVal As Boolean = False Try boolVal = System.Convert.ToBoolean(stringVal) If boolVal Then outputBlock.Text &= String.Format( _ "String is equal to System.Boolean.TrueString.") & vbCrLf Else outputBlock.Text &= String.Format( _ "String is equal to System.Boolean.FalseString.") & vbCrLf End If Catch exception As System.FormatException outputBlock.Text &= String.Format( _ "The string must equal System.Boolean.TrueString " + _ "or System.Boolean.FalseString.") & vbCrLf End Try ' A conversion from bool to string will always succeed. stringVal = System.Convert.ToString(boolVal) outputBlock.Text &= String.Format("{0} as a String is {1}", _ boolVal, stringVal) & vbCrLf End Sub
Show: