title: C# - Write to a datatable from delimited string
body: <p>I have a string something like this:</p>
  
  <pre><code>"X","Y","Z"
  "X2","Y2","Z2"
  </code></pre>
  
  <p>i.e, Multiple rows seperated by a new line containing multiple different string values delimited by commas.</p>
  
  <p>How could I create a function to input these values into a datatable like this:</p>
  
  <pre><code>"X" "Y" "Z"
  "X2" "Y2" "Z2"
  </code></pre>
  
  <p>for any number of rows and columns in my string?</p>
  
  <p>Here's what I have so far:</p>
  
  <pre><code>public static DataTable writeToDT(string data) //Write to datatable from string
      {
          DataTable dataTable = new DataTable();
          foreach (string header in csvHeader)
          {
              dataTable.Columns.Add(header);
          }
          using (StringReader reader = new StringReader(data))
          {
              string line;
              while ((line = reader.ReadLine()) != null)
              {
                  DataRow dataRow = dataTable.NewRow();
              }
          }
          return dataTable;
      }
  </code></pre>
  
  <p>Where <code>csvheader</code> is an array already filled with the headers in my data.<br>
  I believe this creates an empty datatable with the right amount of rows and columns, but I'm not sure how to fill it with the string data I have.</p>
  
  <p>Thanks in advance.</p>