title: C# Pass lambda expression field into method and use field in linq query
body: <p>How can I pass a field (via lambda expression) into a method and then use that field as part of a linq query?</p>
  
  <p>I would like to call the method something like</p>
  
  <pre><code>IDictionary&lt;string, string&gt; stuff = foo(items, otherItems, otherItems =&gt; otherItems.FieldToUse)
  </code></pre>
  
  <p>I'm not sure how I would write the method, but I would want to use it sort of like the code below. I know I could use generics and pass the field name (via a string) into the method, but even then I don't know how I would use it in the linq query as follows. Also, I like using lambda, since I could just rename the field anytime I choose.</p>
  
  <pre><code>private IDictionary&lt;string, string&gt; foo&lt;TModel&gt;(IEnumerable&lt;string&gt; items, IEnumerable&lt;TModel&gt; otherItems, object FieldToUse)
      {
          //this will return a list of key value pairs of rowIDs and equipment
          IDictionary&lt;string, string&gt; x = (from o in otherItems
                                           join i in items on o.FieldToUse.ToString() equals i //joining on the equipment assetcode
                                           select new { rowID = o.RowID, item = i }).ToDictionary(k =&gt; k.rowID.ToString(), v =&gt; v.item);
          return x;
      }
  </code></pre>
  
  <p>Clarification: FieldToUse is a property or field of TModel</p>