title: C# looping through List<dictionary<string,string>> to populate a DataTable
body: <p>I need to loop through a List of Dictionaries </p>
  
  <pre><code>List&lt;Dictionary&lt;string,string&gt;&gt; 
  </code></pre>
  
  <p>to populate a DataTable. Each Dictionary in the list has a Key, which needs to be the column name, and a Value which is what's in that column. The list contains 225 dictionaries (225 rows to the table).</p>
  
  <pre><code>List&lt;Dictionary&lt;string, string&gt;&gt; myList = 
         JsonConvert.DeserializeObject&lt;List&lt;Dictionary&lt;string, string&gt;&gt;&gt;(jsonRep);
  DataTable dt = new DataTable();
  
      //loop through list, loop through dictionaries, add keys as columns, 
      //values as rows.                     
  </code></pre>
  
  <p>so far, I have been trying..</p>
  
  <pre><code>//get max columns
  int columns = myList[0].Count; &lt;--gives me 13
  //add columns
  for (int i = 0; i &lt; columns; i++)
     dt.Columns.Add(string myList[i].Keys);  &lt;--somehow get to the key in dict to add as column names         
  //add rows
  foreach (var x in myList)
  {
       dt.Rows.Add(x); &lt;--not working
  }
  jsonReprValue = dt; &lt;--save new DataTable to var jsonReprValue
  </code></pre>
  
  <p>How do I do this correctly? 
  Thanks!</p>