Convert.ToBoolean Method (Object, IFormatProvider)

 

Converts the value of the specified object to an equivalent Boolean value, using the specified culture-specific formatting information.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)

static member ToBoolean : 
        value:Object *
        provider:IFormatProvider -> bool

Parameters

value
Type: System.Object

An object that implements the IConvertible interface, or null.

provider
Type: System.IFormatProvider

An object that supplies culture-specific formatting information.

Return Value

Type: System.Boolean

true or false, which reflects the value returned by invoking the IConvertible.ToBoolean method for the underlying type of value. If value is null, the method returns false.

Exception Condition
FormatException

value is a string that does not equal TrueString or FalseString.

InvalidCastException

value does not implement the IConvertible interface.

-or-

The conversion of value to a Boolean is not supported.

provider enables the user to specify culture-specific conversion information about the contents of value. The base types ignore the provider parameter; however, the parameter may be used if value is a user-defined type that implements the IConvertible interface.

The following example defines a class that implements IConvertible and a class that implements IFormatProvider. Objects of the class that implements IConvertible hold an array of Double values. An object of each class is passed to the ToBoolean(Object, IFormatProvider) method. This method returns true if any of the non-discarded array values are non-zero. The IFormatProvider object determines how elements are discarded for this calculation.

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show: