I have written a program wherein I fetch a data from an API and the built in API Parser stores the data retrieved in Multi-dimensional array format. I am converting the Multi-dimensional array into DataTable using the codes below:
for (i = mdArray.GetLowerBound(0); i <= mdArray.GetUpperBound(0); ++i)
{
DataRow myRow = null;
myRow = dtResults.NewRow();
for (j = mdArray.GetLowerBound(1); j <= mdArray.GetUpperBound(1); ++j)
{
myRow[Convert.ToInt32(j)] = mdArray[i, j];
}
dtResults.Rows.Add(myRow);
}
mdArray is the multi dimentional array i am referring to.
The above codes works fine when the size or length of the array is less than 100. However, for bigger sizes, like >5000 elements, it takes me too much time to insert the data from array to the DataTable I am building on the fly since i am looping for each element.
Is there a way wherein we can convert Multi Dimentional Array directly to DataTable without doing looping to each element to maximize the performance?
Appreciate your help.
Thank you.