Convert.ToBoolean (Object) converts object to Boolean value.
Class Sample
Public Shared Sub Main()
Dim objects() As Object = {-24, 0, "12.7", String.Empty,"1asdf", "false", Nothing, _
New System.Collections.ArrayList() }
For Each obj As Object In objects
If obj IsNot Nothing Then
Console.Write("{0,-40} --> ", _
String.Format("{0} ({1})", obj, obj.GetType().Name))
Else
Console.Write("{0,-40} --> ", "Nothing")
End If
Try
Console.WriteLine("{0}", Convert.ToBoolean(obj))
Catch e As FormatException
Console.WriteLine("Bad Format")
Catch e As InvalidCastException
Console.WriteLine("No Conversion")
End Try
Next
End Sub
End Class
Related examples in the same category