title: Most efficient way of converting a DataTable to CSV
body: <p>I'm working with DataTable's and I need to convert them to a CSV file format. Most of the tables I am working with have over 50,000 records so I'm trying to minimize the time it takes to convert them.</p>
  
  <p>Here is my current method:</p>
  
  <pre><code>    public static string table_to_csv(DataTable table)
      {
          string file = "";
  
          foreach (DataColumn col in table.Columns)
              file = string.Concat(file, col.ColumnName, ",");
  
          file = file.Remove(file.LastIndexOf(','), 1);
          file = string.Concat(file, "\r\n");
  
          foreach (DataRow row in table.Rows)
          {
              foreach (object item in row.ItemArray)
                  file = string.Concat(file, item.ToString(), ",");
  
              file = file.Remove(file.LastIndexOf(','), 1);
              file = string.Concat(file, "\r\n");
          }
  
          return file;
      }
  </code></pre>
  
  <p>Is there any way I can improve the efficiency of this method? I'm welcome to any modifications and ideas that you have!</p>