title: IEnumerable foreach, do something different for the last element
body: <p>I have an <a href="http://msdn.microsoft.com/en-us/library/9eekhta0.aspx"><code>IEnumerable&lt;T&gt;</code></a>. I want to do one thing for each item of the collection, except the last item, to which I want to do something else. How can I code this neatly? In Pseudocode</p>
  
  <pre><code>foreach (var item in collection)
  {
      if ( final )
      {
          g(item)
      }
      else
      {
          f(item)
      }
  }
  </code></pre>
  
  <p>So if my IEnumerable were <code>Enumerable.Range(1,4)</code> I'd do f(1) f(2) f(3) g(4). NB. If my IEnumerable happens to be length 1, I want g(1).</p>
  
  <p>My IEnumerable happens to be kind of crappy, making <code>Count()</code> as expensive as looping over the whole thing.</p>