title: What is the behaviour of the '==' operator for a generic type value and the 'default' keyword?
body: <p>Part 1 of the question:
  In the following code why does <code>value == default</code> compile fine but the other alternatives do not?</p>
  
  <pre class="lang-cs prettyprint-override"><code>bool MyEqual&lt;T&gt;(T value)
  {
      T value2 = default;
      if (value == value2)     // Error: Operator '==' cannot be applied to operands of type 'T' and 'T'
          return true;
      if (value == default(T)) // Error: Operator '==' cannot be applied to operands of type 'T' and 'T'
          return true;
      if (value == default)    // No error
          return true;
      return false;
  }
  </code></pre>
  
  <p>Part 2 of the question:
  In the following code, why do the first three prints show <code>false</code> and the other three show <code>true</code>?</p>
  
  <pre class="lang-cs prettyprint-override"><code>bool MyEqual&lt;T&gt;(T value)
  {
      if (value == default)
          return true;
      return false;
  }
  
  Console.WriteLine($"{MyEqual&lt;int&gt;(0)}");                  // False
  Console.WriteLine($"{MyEqual&lt;int&gt;(default)}");            // False
  Console.WriteLine($"{MyEqual&lt;int&gt;(default(int))}");       // False
  
  Console.WriteLine($"{MyEqual&lt;string&gt;(null)}");            // True
  Console.WriteLine($"{MyEqual&lt;string&gt;(default)}");         // True
  Console.WriteLine($"{MyEqual&lt;string&gt;(default(string))}"); // True
  </code></pre>
  
  <p>To sum it up: What is the behaviour of the expression <code>value == default</code>?</p>
  
  <p>EDIT: Please do not mark it as a duplicate of this other question, because that one addresses a different case, <code>value == default(T)</code> and not <code>value == default</code>:
  <a href="https://stackoverflow.com/questions/2432909/what-does-defaultobject-do-in-c">What does default(object); do in C#?</a>
  Also, my question is regarding the odd behaviour when using the '==' operator as I explain above.</p>