title: How do I override the equals operator == for an interface in C#?
body: <p>I have defined the following interface:</p>
  <pre><code>public interface IHaveAProblem
  {
      string Issue { get; set; }
  }
  </code></pre>
  <p>And here is the implementation of <code>IHaveAProblem</code>:</p>
  <pre><code>public class SomeProblem : IHaveAProblem
  {
      public string Issue { get; set; }
  
      public override bool Equals(object obj)
      {
          SomeProblem otherObj = obj as SomeProblem;
  
          if (otherObj == null)
          {
              return false;
          }
  
          return this.Issue == otherObj.Issue;
      }
  
      public override int GetHashCode()
      {
          return base.GetHashCode();
      }
      
      public static bool operator ==(SomeProblem rhs, SomeProblem lhs)
      {
          // Null check
          if (Object.ReferenceEquals(rhs, null) || Object.ReferenceEquals(lhs, null))
          {
              if (Object.ReferenceEquals(rhs, null) &amp;&amp; Object.ReferenceEquals(lhs, null))
              {
                  // Both are null.  They do equal each other
                  return true;
              }
  
              // Only 1 is null the other is not so they do not equal
              return false;
          }
  
          return rhs.Equals(lhs);
      }
  
      public static bool operator !=(SomeProblem rhs, SomeProblem lhs)
      {
          // Null check
          if (Object.ReferenceEquals(rhs, null) || Object.ReferenceEquals(lhs, null))
          {
              if (Object.ReferenceEquals(rhs, null) &amp;&amp; Object.ReferenceEquals(lhs, null))
              {
                  // Both are null.  They do equal each other
                  return false;
              }
  
              // Only 1 is null the other is not so they do not equal
              return true;
          }
  
          return !rhs.Equals(lhs);
      }
  }
  </code></pre>
  <p>When I use the object, I can get the correct results for the <code>==</code> compare:</p>
  <pre><code>SomeProblem firstTest = new SomeProblem()
      {
          Issue = &quot;Hello World&quot;
      };
  
  SomeProblem secondTest = new SomeProblem()
      {
          Issue = &quot;Hello World&quot;
      };
  
  // This is true
  bool result = firstTest == secondTest;
  </code></pre>
  <p>However, when I try to compare the interfaces, it is doing a memory compare rather than the operator <code>==</code> on <code>SomeProblem</code>:</p>
  <pre><code>IHaveAProblem firstProblem = new SomeProblem()
      {
          Issue = &quot;Hello World&quot;
      };
  
  IHaveAProblem secondProblem = new SomeProblem()
      {
          Issue = &quot;Hello World&quot;
      };
  </code></pre>
  <p>Is it possible to have the interface use the <code>==</code> on <code>SomeProblem</code> rather than a memory compare?</p>
  <p>I know I can do a <code>firstProblem.Equals(secondProblem)</code> and get the proper results. However, I am creating a framework and I will not know how it is used in the end.  I thought <code>==</code> would work correctly.</p>