title: Copy DataTable.Rows to DataRow[]. Faster way then Select() with the same functionality?
body: <p>I have now a problem with a very old system of ours. (!<em>It is more then 7 years old and I have no budget and resources to make bigger change in the structure, so the decision to improve the old logic as many as we can.</em>!)</p>
  
  <p>We have an own written gridcontrol. Basically it is like a normal ASP.NET grid, you can add, change, delete elements. </p>
  
  <p>The problem is that the grid has a <code>BindGrid()</code> method, where for further usage, the rows of the datasource table copied into a <code>DataRow[]</code>. I need to keep the <code>DataRow[]</code>, but I would like to implement the best way to copy the source from the the table into the array.</p>
  
  <p>The current solution:</p>
  
  <pre><code>DataRow[] rows = DataSource.Select("1=1", SortOrderString);
  </code></pre>
  
  <p>As I experienced so far, if I need to get a specified sort, that could be the best way (I'm also interested if it has a quicker way or not.)</p>
  
  <p>BUT there are some simplified pages, where the SortOrder is not needed. </p>
  
  <p>So I could make two method one for the sort order and one for without.
  The real problem is the second one:</p>
  
  <pre><code> DataRow[] rows = DataSource.Select("1=1");
  </code></pre>
  
  <p>Because it is very slow. I made some test and it is kind of <strong>15 times slower</strong> then the CopyTo() solution:</p>
  
  <pre><code>DataRow[] rows = new DataRow[DataSource.Rows.Count];
  DataSource.Rows.CopyTo(rows,0);
  </code></pre>
  
  <p>I would like to use the faster way, BUT when I made the tests some old function simply crashed. It seems, there is an other difference, what I only noticed now: 
  <strong>The Select() gets the rows like the RowChanges are accepted.</strong></p>
  
  <p>So if I deleted a row, and I do not use the <code>AcceptRowChanges()</code> (<em>I can't do that unfortunately</em>), then with <code>Select("1=1")</code> the row is in the <code>DataSource</code> but not in the <code>DataRow[]</code>.</p>
  
  <p>With a simple <code>.CopyTo()</code> the row is there, and that is a bad news for me.</p>
  
  <p><strong>My questions are:</strong></p>
  
  <p>1) Is the Select("1=1") the best way to get the rows by the RowChanges? (I doubt a bit, because it is like 6 year old part)</p>
  
  <p>2) And if 1) is not, is it possible to achieve a faster way with the same result than the .Select("1=1") ?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Here is a very basic test app, what I used for speedtesting:</p>
  
  <pre><code>DataTable dt = new DataTable("Test");
  
  dt.Columns.Add("Id", typeof (int));
  dt.Columns.Add("Name", typeof(string));
  
  for (int i = 0; i &lt; 10000; i++)
  {
      DataRow row = dt.NewRow();
      row["ID"] = i;
      row["Name"] = "Name" + i;
      dt.Rows.Add(row);
  }
  
  dt.AcceptChanges();
  DateTime start = DateTime.Now;
  
  DataRow[] rows = dt.Select();
  
  /*DataRow[] rows = new DataRow[dt.Rows.Count];
  dt.Rows.CopyTo(rows,0);*/
  
  Console.WriteLine(DateTime.Now - start);
  </code></pre>