Export (0) Print
Expand All

BigInteger.Equals Method (Object)

Returns a value that indicates whether the current instance and a specified object have the same value.

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

public override bool Equals(
	Object obj
)

Parameters

obj
Type: System.Object
The object to compare.

Return Value

Type: System.Boolean
true if the obj parameter is a BigInteger object or a type capable of implicit conversion to a BigInteger value, and its value is equal to the value of the current BigInteger object; otherwise, false.

If the obj parameter is not a BigInteger value, but it is a data type for which an implicit conversion is defined, the Equals(Object) method converts obj to a BigInteger value before it performs the comparison. If obj is not a BigInteger value and cannot be implicitly converted to BigInteger, the method returns false. If no conversion from obj to a BigInteger value exists, the method does not throw an exception; instead, it returns false.

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

The following example compares the approximate distance of several stars from Earth with the distance of Epsilon Indi from Earth to determine whether they are equal. The example uses each overload of the Equals method to test for equality.


const long LIGHT_YEAR = 5878625373183;

BigInteger altairDistance = 17 * LIGHT_YEAR;
BigInteger epsilonIndiDistance = 12 * LIGHT_YEAR;
BigInteger ursaeMajoris47Distance = 46 * LIGHT_YEAR;
long tauCetiDistance = 12 * LIGHT_YEAR;
ulong procyon2Distance = 12 * LIGHT_YEAR;
object wolf424ABDistance = 14 * LIGHT_YEAR;

outputBlock.Text += "Approx. equal distances from Epsilon Indi to:" + "\n";
outputBlock.Text += String.Format("   Altair: {0}",
                  epsilonIndiDistance.Equals(altairDistance)) + "\n";
outputBlock.Text += String.Format("   Ursae Majoris 47: {0}",
                  epsilonIndiDistance.Equals(ursaeMajoris47Distance)) + "\n";
outputBlock.Text += String.Format("   TauCeti: {0}",
                  epsilonIndiDistance.Equals(tauCetiDistance)) + "\n";
outputBlock.Text += String.Format("   Procyon 2: {0}",
                  epsilonIndiDistance.Equals(procyon2Distance)) + "\n";
outputBlock.Text += String.Format("   Wolf 424 AB: {0}",
                  epsilonIndiDistance.Equals(wolf424ABDistance)) + "\n";
// The example displays the following output:
//    Approx. equal distances from Epsilon Indi to:
//       Altair: False
//       Ursae Majoris 47: False
//       TauCeti: True
//       Procyon 2: True
//       Wolf 424 AB: False      


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