title: C# - Using equals operators and methods between child and parent classes pointing to the same memory location
body: <p>So, I have searched all over stackoverflow and can't seem to find just the right answer to my question.</p>
  
  <p>My question is, will equality comparison between a child object and a parent object ever return false when they point to the same memory location, and if so why? Meaning, am I soley comparing a single pointer? Or is there more going on in the background? This is related to the question "How does the compiler "see" the type of the object, and differentiate between the parent and the child (while still equating their pointers)?"</p>
  
  <p>I was trying to understand this by looking at the references <a href="http://www.albahari.com/valuevsreftypes.aspx" rel="nofollow noreferrer">here</a> and <a href="https://stackoverflow.com/questions/9491896/how-are-c-sharp-object-references-represented-in-memory-at-runtime-in-the-clr">here</a>.</p>
  
  <p>Code example,</p>
  
  <pre><code>ChildType childTypeObject = new ChildType();
  
  ParentType parentTypeObject = childTypeObject as ParentType;
  
  if (parentTypeObject == childTypeObject)
  {
      // Will this always get executed?
  }
  </code></pre>
  
  <p><strong>EDIT:</strong></p>
  
  <p>(This is assuming the child class has not overloaded the == operator. So, if you like, use the ReferenceEquals() comparison instead.)</p>