Sorry, what temporary object[] is that?
That would be this then:
public static System.Data.DataTable ToDataTable(this object[,] array)
{
System.Data.DataTable table
= new System.Data.DataTable(); if (array != null)
{
int rowMin = array.GetLowerBound(0), rowMax = array.GetUpperBound(0);
int colMin = array.GetLowerBound(1), colMax = array.GetUpperBound(1);
object[] items
= new object[colMax
- colMin
+ 1];
for (int i = colMin; i <= colMax; i++)
{
table
.Columns.Add(array
[rowMin, i
].ToString(),
typeof(object)); }
for (int i = rowMin + 1; i <= rowMax; i++)
{
for (int j = colMin; j <= colMax; j++)
{
items[j - colMin] = array[i, j];
}
table.Rows.Add(items);
}
}
return table;
}
You could argue that it is an intermediate data structure, which appears to have a point. Would anyone care to time the difference?
As I mentioned previously, it depends on where the data comes from
and what form it has initially. If the data comes from excel and it has
to be gotten one cell at a time, there's not much difference between
putting it in a 2D array or a List/array of single-dimensional arrays, but
if the data is coming over as a 2D array then it could be a wash.