title: Fastest way to create DataTable from List without for loop
body: <p>We have a <strong>huge</strong> list (say <strong>100,000</strong>) which needs to be converted to <code>DataTable</code> for <code>SqlBulkcopy</code>. </p>
  
  <p>Can you guide what could be the fastest way to do this without using for loop?
  For now we are doing it like - in below code <code>listDos</code> is object list</p>
  
  <pre><code>using (var dataTable = new DataTable(dataTableName))
  {
      dataTable.Locale = CultureInfo.CurrentCulture;
      var columns = new[]
          {
               new DataColumn("Id", typeof(int)),
               new DataColumn("FkId", typeof(int)),
               new DataColumn("Status", typeof(string)),
               new DataColumn("RecordFrom", typeof(DateTime))
          };
  
      dataTable.Columns.AddRange(columns);
  
  
      foreach (ObjectDo listDo in listDos)
      {
          var row = dataTable.NewRow();
  
          if (rebuildDo.Id != null) row["Id"] = rebuildDo.Id;
  
          if (rebuildDo.FkId!= null) row["FkId"] = rebuildDo.FkId;
  
          row["Status"] = rebuildDo.Status;
  
          row["RecordFrom"] = rebuildDo.RecordFrom;
  
          dataTable.Rows.Add(row);
      }
  
      return dataTable;
  }
  </code></pre>