title: Why is Linq.Sum() with decimals ambiguous between int and int?
body: <p><em>short:</em><br>
  I have a method <code>decimal GetAmount(IThing thing)</code>. Using <code>things.Sum(GetAmount)</code> results in a CS0121 error: call is ambiguous between <code>Sum(Func&lt;T, int&gt;)</code> and <code>Sum(Func&lt;T, int?&gt;)</code>. Why?</p>
  
  <p><em>longer:</em></p>
  
  <pre><code>public interface IThing { }
  public class Sample {
      public decimal GetAmount(IThing thing) { return 0; }
      public decimal Total(IThing[] things) { return things.Sum(GetAmount); }
  }
  </code></pre>
  
  <blockquote>
    <p>Error CS0121  The call is ambiguous between the following methods or
    properties: <code>'Enumerable.Sum&lt;TSource&gt;(IEnumerable&lt;TSource&gt;,
    Func&lt;TSource, int&gt;)'</code> and
    <code>'Enumerable.Sum&lt;TSource&gt;(IEnumerable&lt;TSource&gt;, Func&lt;TSource, int?&gt;)'</code></p>
  </blockquote>
  
  <p>I would somewhat understand if the compiler was confused between <code>decimal</code> and <code>decimal?</code> or if the compiler couldn't pick any of the many Sum overloads. But why/how did it limit itself to only <code>int</code> and <code>int?</code></p>
  
  <p>Btw, VS / R# 'helpfully' highlights passing <code>GetAmount</code> to <code>.Sum()</code> as an error and suggests passing an int returning method instead. The compiler doesn't flag this part as a second error. Changing <code>GetAmount</code> to <code>int GetAmount(IThing thing)</code> actually does 'solve' the compiler error.</p>
  
  <p>ps. I'm not looking for a solution to the compiler error. I know I can turn GetAmount into <code>Func&lt;IThing, decimal&gt; GetAmount { get; }</code> or implement Total like <code>things.Sum(thing =&gt; GetAmount(thing))</code>. And as suggested by @IvanStoev, <code>things.Sum(new Func&lt;IThing, decimal&gt;(GetAmount))</code> works (for me) as well.</p>