title: Operator with C# dynamic?
body: <p>I have this function:</p>
  
  <pre><code>static void Func1&lt;T&gt;(T x, T y)
  {
      dynamic result = ((dynamic)x + y); //line 1
      dynamic result2 = (x + y);         //line 2
  }
  </code></pre>
  
  <p>This func can be executed as <code>Func(1,2);</code> However, line 1 is <em>OK</em>, while line 2 goes <em>BANG</em> (at compile time).</p>
  
  <p>The exception thrown from line 2 is: </p>
  
  <blockquote>
    <p>Operator '+' cannot be applied to operands of type 'T' and 'T'</p>
  </blockquote>
  
  <p>So, we need to create an operator overload. Okay, so far so good.</p>
  
  <p><strong>But what about line 1? Shouldn't it need a dynamic cast also on <code>y</code>?</strong></p>
  
  <p><code>((dynamic)x + (dynamic)y);</code></p>
  
  <p>I understand that it is being evaluated at runtime, but why does the C# compiler accept the <code>+</code> operator  in line 1 (i.e. wrongly assume that T can be <code>+</code> to something else)?</p>