Export (0) Print
Expand All

Single.CompareTo Method (Object)

Compares this instance to a specified object and returns an integer that indicates whether the value of this instance is less than, equal to, or greater than the value of the specified object.

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

abstract CompareTo : 
        value:Object -> int 
override CompareTo : 
        value:Object -> int 

Parameters

value
Type: System.Object
An object to compare, or a null reference (Nothing in Visual Basic).

Return Value

Type: System.Int32
A signed number indicating the relative values of this instance and value.

Return Value

Description

Less than zero

This instance is less than value.

-or-

This instance is not a number (NaN) and value is a number.

Zero

This instance is equal to value.

-or-

This instance and value are both not a number (NaN), PositiveInfinity, or NegativeInfinity.

Greater than zero

This instance is greater than value.

-or-

This instance is a number and value is not a number (NaN).

-or-

value is a null reference (Nothing in Visual Basic).

Implements

IComparable.CompareTo(Object)

ExceptionCondition
ArgumentException

value is not a Single.

Any instance of Single, regardless of its value, is considered greater than a null reference (Nothing in Visual Basic).

The value parameter must be a null reference (Nothing in Visual Basic) or an instance of Single; otherwise, an exception is thrown.

This method is implemented to support the IComparable interface. Note that, although a NaN is not considered to be equal to another NaN (even itself), the IComparable interface requires that A.CompareTo(A) return zero.

Precision in Comparisons

The precision of floating-point numbers beyond the documented precision is specific to the implementation and version of the .NET Framework. Consequently, a comparison of two particular numbers might change between versions of the .NET Framework because the precision of the numbers' internal representation might change.

The following code example demonstrates the CompareTo method.

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

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

ADD
Show:
© 2014 Microsoft