title: C# lambda expressions as function arguments
body: <p>I've been busy diving into lambda expressions recently, and there's some specific functionality that I've been meaning to learn but just couldn't seem to make heads or tails of.</p>
  
  <p>Suppose that I have the following logic in my code:</p>
  
  <pre><code>List&lt;A&gt; foo; // assuming this is populated
  string[] bar = foo.Select&lt;A,string&gt;(x =&gt; x.StringProperty).ToArray&lt;string&gt;();
  </code></pre>
  
  <p>Now, I want to perhaps abstract that whole operation into a handler method so that I can do this instead:</p>
  
  <pre><code>string[] bar = MakeArray&lt;A,string&gt;(foo, x =&gt; x.StringProperty);
  int[] foobar = MakeArray&lt;A,int&gt;(foo, x =&gt; x.IntegerProperty);
  </code></pre>
  
  <p>How would I go about with writing that method's body? I foresee declaring the signature as something like:</p>
  
  <pre><code>U[] MakeArray&lt;T,U&gt;( /* some lambda magic? */ ) where T : IEntity {}
  </code></pre>
  
  <p>but I don't know how to specify that I'm expecting a lambda expression as the method argument, and how that translates exactly into the body of the method.</p>
  
  <p>Can anybody show me how to create the <code>MakeArray()</code> function above? I'm pretty sure that once I see how it's done, that I can pick it up from there.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>As pointed out in the comments, <code>MakeArray()</code> needed a reference to the <code>IEnumerable&lt;&gt;</code>. Updated to reflect that.</p>