Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

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);
outputBlock.Text += String.Format("{0} {1} = {2} {3} : {4}",
                  bigIntValue.GetType().Name, bigIntValue,
                  byteValue.GetType().Name, byteValue,
                  bigIntValue.Equals(byteValue)) + "\n";

sbyte sbyteValue = -16;
bigIntValue = new BigInteger(sbyteValue);
outputBlock.Text += String.Format("{0} {1} = {2} {3} : {4}",
                  bigIntValue.GetType().Name, bigIntValue,
                  sbyteValue.GetType().Name, sbyteValue,
                  bigIntValue.Equals(sbyteValue)) + "\n";

short shortValue = 1233;
bigIntValue = new BigInteger(shortValue);
outputBlock.Text += String.Format("{0} {1} = {2} {3} : {4}",
                  bigIntValue.GetType().Name, bigIntValue,
                  shortValue.GetType().Name, shortValue,
                  bigIntValue.Equals(shortValue)) + "\n";

ushort ushortValue = 64000;
bigIntValue = new BigInteger(ushortValue);
outputBlock.Text += String.Format("{0} {1} = {2} {3} : {4}",
                  bigIntValue.GetType().Name, bigIntValue,
                  ushortValue.GetType().Name, ushortValue,
                  bigIntValue.Equals(ushortValue)) + "\n";

int intValue = -1603854;
bigIntValue = new BigInteger(intValue);
outputBlock.Text += String.Format("{0} {1} = {2} {3} : {4}",
                  bigIntValue.GetType().Name, bigIntValue,
                  intValue.GetType().Name, intValue,
                  bigIntValue.Equals(intValue)) + "\n";

uint uintValue = 1223300;
bigIntValue = new BigInteger(uintValue);
outputBlock.Text += String.Format("{0} {1} = {2} {3} : {4}",
                  bigIntValue.GetType().Name, bigIntValue,
                  uintValue.GetType().Name, uintValue,
                  bigIntValue.Equals(uintValue)) + "\n";

long longValue = -123822229012;
bigIntValue = new BigInteger(longValue);
outputBlock.Text += String.Format("{0} {1} = {2} {3} : {4}",
                  bigIntValue.GetType().Name, bigIntValue,
                  longValue.GetType().Name, longValue,
                  bigIntValue.Equals(longValue)) + "\n";
// 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


Silverlight

Supported in: 5, 4

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show:
© 2015 Microsoft