title: Call method on all members of IEnumerable
body: <p>I've been playing around with some c# extensions lately and I have a question. I made a 'ForEach' extension for IEnumerables (List has one from Linq, though none exists for IEnumerables.) It's a very simple one:</p>
  
  <pre><code>public static void ForEach&lt;T&gt; (this IEnumerable&lt;T&gt; source, Action&lt;T&gt; action)
  {
      foreach (T element in source) {
          action(element);
      }
  }
  </code></pre>
  
  <p>And you call it like <code>MyArray.ForEach(element=&gt;element.ElementMethod());</code></p>
  
  <p>Though now I was wondering, can I take it one step further and make it something like: <code>MyArray.ForEach(ElementMethod);</code>?</p>
  
  <p>Edit: Already some interesting answers, though I was trying something like this:</p>
  
  <pre><code>public static void CallOnEach&lt;T&gt; (this IEnumerable&lt;T&gt; source, Action action)
  {
      foreach (T element in source) {
          element.action();
      }
  }
  </code></pre>
  
  <p>Of course the compiler can't know that 'action' is a method of T, so this doesn't work :( Perhaps there's a way to ensure the compiler of this? Something like <code>public static void CallOnEach&lt;T&gt; (this IEnumerable&lt;T&gt; source, Action action) where action isFunctionOf T</code></p>
  
  <p>Thanks!</p>