title: How does native implementation of ValueType.GetHashCode work?
body: <p>I created two structures of <code>TheKey</code> type k1={17,1375984} and k2={17,1593144}.
  Obviosly the pointers in the second fields are different. But both get same hash code=346948941.
  Expected to see different hash codes. See the code below.</p>
  
  <pre><code>struct TheKey
  {
      public int id;
      public string Name;
  
      public TheKey(int id, string name)
      {
         this.id = id;
         Name = name;
     }
  }
  
  static void Main() {
      // assign two different strings to avoid interning
      var k1 = new TheKey(17, "abc");
      var k2 = new TheKey(17, new string(new[] { 'a', 'b', 'c' }));
  
      Dump(k1); // prints the layout of a structure
      Dump(k2);
  
      Console.WriteLine("hash1={0}", k1.GetHashCode());
      Console.WriteLine("hash2={0}", k2.GetHashCode());
  }
  
  unsafe static void Dump&lt;T&gt;(T s) where T : struct
  {
      byte[] b = new byte[8];
      fixed (byte* pb = &amp;b[0])
      {
          IntPtr ptr = new IntPtr(pb);
          Marshal.StructureToPtr(s, ptr, true);
  
          int* p1 = (int*)(&amp;pb[0]); // first 32 bits
          int* p2 = (int*)(&amp;pb[4]);
  
          Console.WriteLine("{0}", *p1);
          Console.WriteLine("{0}", *p2);
      }
  }
  </code></pre>
  
  <p><b>Output:</b><br/>
  17<br/>
  1375984<br/>
  17<br/>
  1593144<br/>
  hash1=346948941<br/>
  hash2=346948941<br/></p>