This documentation is archived and is not being maintained.

BigInteger.Compare Method

Compares two BigInteger values and returns an integer that indicates whether the first value is less than, equal to, or greater than the second value.

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

Public Shared Function Compare ( _
	left As BigInteger, _
	right As BigInteger _
) As Integer


Type: System.Numerics.BigInteger
The first value to compare.
Type: System.Numerics.BigInteger
The second value to compare.

Return Value

Type: System.Int32
A signed integer that indicates the relative values of left and right, as shown in the following table.



Less than zero

left is less than right.


left equals right.

Greater than zero

left is greater than right.

Although the BigInteger type has no fixed range, comparisons of BigInteger values are not characterized by the lack of precision that characterizes the comparison of floating-point numbers. The following example compares two BigInteger values that differ by one and that each have 1,896 digits. The Compare method correctly reports that the two values are not equal.

Dim number1 As BigInteger = BigInteger.Pow(Int64.MaxValue, 100)
Dim number2 As BigInteger = number1 + 1
Dim relation As String = ""
Select Case BigInteger.Compare(number1, number2)
   Case -1
      relation = "<"
   Case 0
      relation = "="
   Case 1
      relation = ">"
End Select            
Console.WriteLine("{0} {1} {2}", number1, relation, number2)
' The example displays the following output:
'    3.0829940252776347122742186219E+1896 < 3.0829940252776347122742186219E+1896

.NET Framework

Supported in: 4

.NET Framework Client Profile

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, 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.