title: Is it better to call ToList() or ToArray() in LINQ queries?
body: <p>I often run into the case where I want to eval a query right where I declare it. This is usually because I need to iterate over it multiple times <em>and</em> it is expensive to compute. For example:</p>
  
  <pre><code>string raw = "...";
  var lines = (from l in raw.Split('\n')
               let ll = l.Trim()
               where !string.IsNullOrEmpty(ll)
               select ll).ToList();
  </code></pre>
  
  <p>This works fine. <strong>But</strong> if I am not going to modify the result, then I might as well call <code>ToArray()</code> instead of <code>ToList()</code>.</p>
  
  <p>I wonder however whether <code>ToArray()</code> is implemented by first calling <code>ToList()</code> and is therefore less memory efficient than just calling <code>ToList()</code>.</p>
  
  <p>Am I crazy? Should I just call <code>ToArray()</code> - safe and secure in the knowledge that the memory won't be allocated twice?</p>