Skip to main content
added 149 characters in body
Source Link
Ankit Goel
  • 181
  • 1
  • 1
  • 5

Is it possible to remove the inner loop by assigning data.Data.Tables[0].Rows[i].ItemArray directly?

object[,] arr = new object[52784, 21];

for (int i = 0; i < data.Data.Tables[0].Rows.Count; i++)
{
    for (int j = 0; j < data.Data.Tables[0].Columns.Count; j++)
    {
        arr[i, j] = data.Data.Tables[0].Rows[i][j];
    }
}

The reason why I need this code is because, I want to write to data of this dataTable to Excel using Interop which requires a 2-D array as input.

Is it possible to remove the inner loop by assigning data.Data.Tables[0].Rows[i].ItemArray directly?

object[,] arr = new object[52784, 21];

for (int i = 0; i < data.Data.Tables[0].Rows.Count; i++)
{
    for (int j = 0; j < data.Data.Tables[0].Columns.Count; j++)
    {
        arr[i, j] = data.Data.Tables[0].Rows[i][j];
    }
}

Is it possible to remove the inner loop by assigning data.Data.Tables[0].Rows[i].ItemArray directly?

object[,] arr = new object[52784, 21];

for (int i = 0; i < data.Data.Tables[0].Rows.Count; i++)
{
    for (int j = 0; j < data.Data.Tables[0].Columns.Count; j++)
    {
        arr[i, j] = data.Data.Tables[0].Rows[i][j];
    }
}

The reason why I need this code is because, I want to write to data of this dataTable to Excel using Interop which requires a 2-D array as input.

fixed formatting
Source Link
SirPython
  • 13.5k
  • 3
  • 38
  • 93

Is it possible to remove the inner loop by assigning data.Data.Tables[0].Rows[i].ItemArraydata.Data.Tables[0].Rows[i].ItemArray directly?

object[,] arr = new object[52784, 21];

for (int i = 0; i < data.Data.Tables[0].Rows.Count; i++)
{
    for (int j = 0; j < data.Data.Tables[0].Columns.Count; j++)
    {
        arr[i, j] = data.Data.Tables[0].Rows[i][j];
    }
}

Is it possible to remove the inner loop by assigning data.Data.Tables[0].Rows[i].ItemArray directly?

object[,] arr = new object[52784, 21];

for (int i = 0; i < data.Data.Tables[0].Rows.Count; i++)
{
    for (int j = 0; j < data.Data.Tables[0].Columns.Count; j++)
    {
        arr[i, j] = data.Data.Tables[0].Rows[i][j];
    }
}

Is it possible to remove the inner loop by assigning data.Data.Tables[0].Rows[i].ItemArray directly?

object[,] arr = new object[52784, 21];

for (int i = 0; i < data.Data.Tables[0].Rows.Count; i++)
{
    for (int j = 0; j < data.Data.Tables[0].Columns.Count; j++)
    {
        arr[i, j] = data.Data.Tables[0].Rows[i][j];
    }
}
Post Reopened by Ismael Miguel, RubberDuck, Vogel612, 200_success
Post Closed as "Not suitable for this site" by Mast, Kaz, Ismael Miguel, SuperBiasedMan, BCdotWEB
edited title
Link
200_success
  • 145.7k
  • 22
  • 191
  • 481

Minimize number of loops Copying data from a table into a two-dimensional array

Source Link
Ankit Goel
  • 181
  • 1
  • 1
  • 5
Loading