title: Can the C# compiler or JIT optimize away a method call in a lambda expression?
body: <p>I'm starting this question after a discussion which started (<a href="https://stackoverflow.com/a/36438566/81179">in comments</a>) on another StackOverflow question, and I'm intrigued to know the answer. Considering the following expression:</p>
  <pre><code>var objects = RequestObjects.Where(r =&gt; r.RequestDate &gt; ListOfDates.Max());
  </code></pre>
  <p>Will there be any (performance) advantage of moving the evaluation of <code>ListOfDates.Max()</code> out of the Where clause in this case, or will 1. the compiler or 2. JIT optimize this away?</p>
  <p>I believe C# will only do constant folding at compile time, and it could be argued that ListOfDates.Max() can not be known at compile time unless ListOfDates itself is somehow constant.</p>
  <p>Perhaps there is another compiler (or JIT) optimization that makes sure that this is only evaluated once?</p>