title: LINQ Lambda vs Query Syntax Performance
body: <p>I saw a LINQ query syntax in my project today which was counting items with a specific condition from a <code>List</code> like this:</p>
  <pre><code>int temp = (from A in pTasks 
              where A.StatusID == (int)BusinessRule.TaskStatus.Pending     
              select A).ToList().Count();
  </code></pre>
  <p>I thought of refactoring it by rewriting it using <code>Count(Func)</code> to make it more readable. I thought it would also be good performance-wise, so I wrote:</p>
  <pre><code>int UnassignedCount = pTasks.Count(x =&gt; x.StatusID == (int)BusinessRule.TaskStatus.Pending);
  </code></pre>
  <p>But when I check using <code>StopWatch</code>, the time elapsed by the lambda expression is always more than the query syntax:</p>
  <pre><code>Stopwatch s = new Stopwatch();
  s.Start();
  int UnassignedCount = pTasks.Count(x =&gt; x.StatusID == (int)BusinessRule.TaskStatus.Pending);
  s.Stop();
  Stopwatch s2 = new Stopwatch();
  s2.Start();
  int temp = (from A in pTasks 
              where A.StatusID == (int)BusinessRule.TaskStatus.Pending
              select A).ToList().Count();
  s2.Stop();
  </code></pre>
  <p>Can somebody explain why it is so?</p>