BigInteger.Equals Method (Int64)

Returns a value that indicates whether the current instance and a signed 64-bit integer have the same value.

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

public bool Equals(
	long other
)

Parameters

other
Type: System.Int64

The signed 64-bit integer value to compare.

Return Value

Type: System.Boolean
true if the signed 64-bit integer and the current instance have the same value; otherwise, false.

If other is a Byte, Int16, Int32, SByte, UInt16, or UInt32 value, it is implicitly converted to an Int64 value when the method is called.

To determine the relationship between the two objects instead of just testing for equality, call the BigInteger.CompareTo(Int64) method.

The following example instantiates a BigInteger object from each integral type except UInt64. It then calls the Equals(Int64) method to compare the BigInteger value with the original integer value that was passed to the BigInteger constructor. As the output shows, the values are equal in each case.

BigInteger bigIntValue; 

byte byteValue = 16;
bigIntValue = new BigInteger(byteValue);
Console.WriteLine("{0} {1} = {2} {3} : {4}", 
                  bigIntValue.GetType().Name, bigIntValue,
                  byteValue.GetType().Name, byteValue, 
                  bigIntValue.Equals(byteValue));

sbyte sbyteValue = -16;
bigIntValue = new BigInteger(sbyteValue);
Console.WriteLine("{0} {1} = {2} {3} : {4}", 
                  bigIntValue.GetType().Name, bigIntValue,
                  sbyteValue.GetType().Name, sbyteValue,
                  bigIntValue.Equals(sbyteValue));

short shortValue = 1233;
bigIntValue = new BigInteger(shortValue);
Console.WriteLine("{0} {1} = {2} {3} : {4}", 
                  bigIntValue.GetType().Name, bigIntValue,
                  shortValue.GetType().Name, shortValue, 
                  bigIntValue.Equals(shortValue));

ushort ushortValue = 64000;
bigIntValue = new BigInteger(ushortValue);
Console.WriteLine("{0} {1} = {2} {3} : {4}", 
                  bigIntValue.GetType().Name, bigIntValue,
                  ushortValue.GetType().Name, ushortValue, 
                  bigIntValue.Equals(ushortValue));

int intValue = -1603854;
bigIntValue = new BigInteger(intValue);
Console.WriteLine("{0} {1} = {2} {3} : {4}", 
                  bigIntValue.GetType().Name, bigIntValue,
                  intValue.GetType().Name, intValue, 
                  bigIntValue.Equals(intValue));

uint uintValue = 1223300;
bigIntValue = new BigInteger(uintValue);
Console.WriteLine("{0} {1} = {2} {3} : {4}", 
                  bigIntValue.GetType().Name, bigIntValue,
                  uintValue.GetType().Name, uintValue, 
                  bigIntValue.Equals(uintValue));

long longValue = -123822229012;
bigIntValue = new BigInteger(longValue);
Console.WriteLine("{0} {1} = {2} {3} : {4}", 
                  bigIntValue.GetType().Name, bigIntValue,
                  longValue.GetType().Name, longValue, 
                  bigIntValue.Equals(longValue));
// The example displays the following output: 
//    BigInteger 16 = Byte 16 : True 
//    BigInteger -16 = SByte -16 : True 
//    BigInteger 1233 = Int16 1233 : True 
//    BigInteger 64000 = UInt16 64000 : True 
//    BigInteger -1603854 = Int32 -1603854 : True 
//    BigInteger 1223300 = UInt32 1223300 : True 
//    BigInteger -123822229012 = Int64 -123822229012 : True

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4

.NET Framework Client Profile

Supported in: 4

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1

Windows Phone 8.1, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft