title: Pass a condition occurring within a foreach loop as a parameter
body: <p>I have a method for adding data from some student objects in a list to a datatable. The method checks for students in the studentList that meet a certain condition and then adds them to the datatable. </p>
  
  <p>I want to specify the condition in the parameter, however I (understandably) get an error when I try to pass in <strong>s.status</strong> as my second string parameter, since <strong>s</strong> doesn't come into play until the foreach loop starts. Is there a way to make this work?        </p>
  
  <pre><code>    public void AddDataTableRows(DataTable datatable, string field, string condition)
      {
         foreach (student s in studentList)
         {
             if (field == condition)
             {
                 datatable.Rows.Add(s.name, 
                     s.totalDays, 
                     s.improveOverall,
                     s.totalClassDays,
                     s.instructor,
                     s.grade);
             }
  
         }
     }
  </code></pre>
  
  <p>The call that I want to make</p>
  
  <pre><code>AddDataTableRows(DataTable1, s.status, "active");
  </code></pre>