Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

ValueType.Equals Method

Indicates whether this instance and a specified object are equal.

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

public override bool Equals(
	Object obj
)

Parameters

obj
Type: System.Object
Another object to compare to.

Return Value

Type: System.Boolean
true if obj and this instance are the same type and represent the same value; otherwise, false.

The default implementation of the Equals method uses reflection to compare the corresponding fields of obj and this instance. Override the Equals method for a particular type to improve the performance of the method and more closely represent the concept of equality for the type.

The following example demonstrates how the Equals method can be overridden by a derived value type.


public struct Complex
{
   public double m_Re;
   public double m_Im;

   public override bool Equals(object ob)
   {
      if (ob is Complex)
      {
         Complex c = (Complex)ob;
         return m_Re == c.m_Re && m_Im == c.m_Im;
      }
      else
      {
         return false;
      }
   }

   public override int GetHashCode()
   {
      return m_Re.GetHashCode() ^ m_Im.GetHashCode();
   }
}


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

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

Community Additions

Show:
© 2014 Microsoft