Skip to main content
.NET Framework Class Library
Int32..::.CompareTo Method (Object)

Compares this instance to a specified object and returns an indication of their relative values.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Syntax
Public Function CompareTo ( _
	value As Object _
) As Integer
public int CompareTo(
	Object value
)
public:
virtual int CompareTo(
	Object^ value
) sealed
abstract CompareTo : 
        value:Object -> int 
override CompareTo : 
        value:Object -> int 

Parameters

value
Type: System..::.Object
An object to compare, or nullNothingnullptra 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.

Zero

This instance is equal to value.

Greater than zero

This instance is greater than value.

-or-

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

Implements

IComparable..::.CompareTo(Object)
Exceptions
ExceptionCondition
ArgumentException

value is not an Int32.

Remarks

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

value must be nullNothingnullptra null reference (Nothing in Visual Basic) or an instance of Int32; otherwise, an exception is thrown.

Version Information

.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
Platforms

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.
Microsoft is conducting an online survey to understand your opinion of the MSDN Web site. If you choose to participate, the online survey will be presented to you when you leave the MSDN Web site.

Would you like to participate?