title: C# better to initialize list then loop over it, or just initialize in loop condition?
body: <p>I end up with a lot of code like this:</p>
  
  <pre><code>List&lt;string&gt; dates = someMethodCall();
  foreach (string dateStr in dates) { }
  </code></pre>
  
  <p>I usually declare the object over which I'm iterating and then use it in the <code>foreach</code> condition out of worry that <code>someMethodCall()</code> would happen for each iteration of the loop.  Is this the case?  I would prefer to do this:</p>
  
  <pre><code>foreach (string dateStr in someMethodCall()) { }
  </code></pre>
  
  <p>But I only want to do that if <code>someMethodCall()</code> happens only once and then its results are cached for each subsequent iteration.</p>