I've an array like this one:
const int dim = 1000;
double[,] array = new double[dim, dim];
Random ran = new Random();
for (int r = 0; r < dim; r++)
for (int c = 0; c < dim; c++)
array[r, c] = (ran.Next(dim));
DataTable d开发者_StackOverflowataTable = new DataTable();
Can I fill the dataTable
with the array
data?
Try something like this:
var dt = new DataTable();
//AddColumns
for (int c = 0; c < dim; c++)
dt.Columns.Add(c.ToString(), typeof(double));
//LoadData
for (int r = 0; r < dim; r++)
dt.LoadDataRow(arry[r]);
You have to set up the Columns and then load one row at a time using
DataTable.LoadDataRow()
which takes object[]
Check out the example in MSDN page.
Yes, you can, but you must add 1000 columns to the table first like this:
dataTable.Columns.Add("Column" + c, typeof(double));
However, the real question is why do you want to do that. DataTable is very ineffective data structure.
精彩评论