I need to declare 32 string arrays containing arrays in C#. Writing it all out works OK similar to this:
string[] row1 = new string[] { "NO.", "DATA BIN", "BIT2", "BIT1", };
string[] row2 = new string[] { "1", DataBin[1], BitLabels[1, 1], BitLabels[0, 1], };
string[] row3 = new string[] { "2", DataBin[2], BitLabels[1, 2], BitLabels[0, 2], };
string[] row4 = new string[] { "3", DataBin[3], BitLabels[1, 3], BitLabels[0, 3], };
But it would be so much cleaner / easier if I could create them like this:
string[] row1 = new string[] { "NO.", "DATA BIN", "BIT2", "BIT1", };
for (int i = 2; i < 33; i++)
{
string[] row(i) = new string[] { Convert.ToString(i), DataBin[i], BitLabels[1, i], BitLabels[0, i], };
}
The problem is that I can't index the instance name (row1 for example)
This is for a DataGridView, so I also need to have something to take care of the following:
object[] rows = new object[] { row1 , row2 , row3 , row4 , row5 , row6 , row7 , row8 , row9 ,
row10 , row11 , row12 , row13 , row14 , row15 , row16 , row17 ,
row18 , row19 , row20 , row21 , row22 , row23 , row24 , row25 ,
row26 , row27 , row28 , row29 , row30 , row31 , row32 , row33 };
foreach (string[] rowArray in rows)
{
myDataGridView.Rows.Add(rowArray);
}
Any suggestions? (sorry many edits for clarity)