System.Boolean.CompareTo Method

Compares this instance to a specified bool object and returns an integer that indicates their relationship to one another.

Syntax

public int CompareTo (bool value)

Parameters

value
A bool object to compare to this instance.

Returns

A signed integer that indicates the relative values of this instance and value.

Less than zero

This instance is false and value is true.

Zero

This instance and value are equal (either both are true or both are false).

Greater than zero

This instance is true and value is false.

Remarks

This method implements the IComparable`1 interface and performs slightly better than the bool.CompareTo(object) method because it does not have to convert the value parameter to an object.

If value has fewer bits (is narrower) than the instance type, some programming languages perform an implicit widening conversion that transforms the value of the parameter into a value with more bits.

For example, suppose the instance type is int and the parameter type is byte. The Microsoft C# compiler generates instructions to represent the value of the parameter as an int object, then generates a int.CompareTo(int) method to compare the int instance and parameter representation.

Consult your programming language's documentation to determine whether its compiler performs implicit widening conversions on numeric types.

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0
Since: .NET 2.0