title: How to implement MaxOrDefault(x => x.SomeInt) LINQ extension?
body: <p>When calling .Max(x => x.SomeInt) on an IEnumerable, you commonly are happy to return "0" if the enumerable contains no elements. However LINQ's implementation of .Max(x => x.SomeInt) crashes as the sequence contains no elements.</p>
  
  <p>Therefore a .MaxOrDefault(x => x.SomeInt) function would be useful.</p>
  
  <p>We should not simply call .Any() then .Max(func) because this causes a legitimate "possible multiple enumeration" warning in Resharper.</p>
  
  <p>I have implemented one as follows:</p>
  
  <pre><code>    public static TResult MaxOrDefault&lt;T, TResult&gt;(this IEnumerable&lt;T&gt; enumerable, Func&lt;T, TResult&gt; func)
      {
          var list = enumerable.ToList();
          if (!list.Any()) return default(TResult);
  
          return list.Max(func);
      }
  </code></pre>
  
  <p>However this has the downside of having to enumerate into a list first, which is suboptimal and should be unnecessary.</p>
  
  <p>Is there a better way?</p>