I have a group DataTablesthat needs to be converted to arrays object[,](not object[][]arrays). What is the most efficient way to do this in terms of performance?
I know that I can do this by first building object[dt.Rows.Count, dt.Columns.Count], then going through the lines and parsing each line into a place in the array, but I am sure that there are other methods, such as using Linq or System.Data- such as dataRow.ToItemArray(), which can be more efficient .
My DataTableshave variable sizes and contain both dates and numbers, which must be formatted accordingly, in addition to strings.
For example, if one of my data tables contained
Id name date value
1 Rachel 1/1/2013 00:00:00 100.0000
2 Joseph 3/31/2012 00:00:00 50.0000
3 Sarah 2/28/2013 00:00:00 75.5000
then i need an array object[,]containing exact data (ideally with headers) but with formatted dates and values
arr[x,0] = row[x].Field<int>("Id");
arr[x,1] = row[x].Field<string>("Name");
arr[x,2] = row[x].Field<DateTime>("Date").ToString("M/d/yy");
arr[x,3] = row[x].Field<decimal>("Value").ToString("C2");
source
share