C# で配列を含む 32 個の文字列配列を宣言する必要があります。すべて書き出すと、次のように問題なく動作します。
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], };
しかし、次のように作成できれば、はるかにクリーン/簡単になります。
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], };
}
問題は、インスタンス名 (row1 など) にインデックスを付けられないことです。
これは DataGridView 用であるため、次の処理を行う必要もあります。
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);
}
助言がありますか?(わかりやすくするために多くの編集を申し訳ありません)