title: Why integer zero does not equal long zero?
body: <p>A strange piece of code I've just discovered in C# (should also be true for other CLI languages using .NET's <code>structs</code>).</p>
  
  <pre class="lang-cs prettyprint-override"><code>using System;
  
  public class Program
  {
      public static void Main(string[] args)
      {
      int a;
      long b;
  
      a = 0;
      b = 0;
  
      Console.WriteLine(a.Equals(b)); // False
      Console.WriteLine(a.Equals(0L)); // False
      Console.WriteLine(a.Equals((long)0)); // False
      Console.WriteLine(a.Equals(0)); // True
      Console.WriteLine(a.Equals(a)); // True
      Console.WriteLine(a == b); // True
      Console.WriteLine(a == 0L); // True
  
      Console.WriteLine();
  
      Console.WriteLine(b.Equals(a)); // True
      Console.WriteLine(b.Equals(0)); // True
      Console.WriteLine(b.Equals((int)0)); // True
      Console.WriteLine(b.Equals(b)); // True
      Console.WriteLine(b == a); // True
      Console.WriteLine(b == 0); // True
      }
  }
  </code></pre>
  
  <p>Two interesting points here (assuming that <code>a</code> is <code>int</code> and <code>b</code> is <code>long</code>):</p>
  
  <ol>
  <li><code>a != b</code>, but <code>b == a</code>;</li>
  <li><code>(a.Equals(b)) != (a == b)</code></li>
  </ol>
  
  <p>Is there any reason why comparison was implemented this way?</p>
  
  <p>Note: .NET 4 was used if it makes any difference.</p>