Convert DataRowCollection to DataRow[]

Viewed 48841

What's the best performing way to convert a DataRowCollection instance to a DataRow[]?

4 Answers
DataRow[] rows = dt.Select();

Assuming you still have access to the datatable.

This is kind of obvious, but:

DataRowCollection.CopyTo(DataRow[] array, Int32 offset) ?

It seems like no matter what, you're going to have to iterate the collection (CopyTo iterates the internal DataRowTree elements).

I suppose you could use reflection to access the non-public tree, but at a significant cost.

Related