以下は、デバッグを開始するとエラーになるコードです。コンボボックス 1 またはコンボボックス 2 からオプションを選択すると、メッセージ ポップアップが表示されます: インデックスが配列の範囲外でした。どうすればこれを解決できますか?
お読みいただきありがとうございます。:)
public Form1()
{
InitializeComponent();
String[] arr1 = new String[2];
arr1[0] = "SG";
arr1[1] = "MY";
comboBox1.Items.AddRange(arr1);
comboBox2.Items.AddRange(arr1);
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
double[,] arr = new double[2, 2];
for(int i = 0; i <2; i++)
{
arr[0, 0] = 1;
arr[0, 1] = 1.24;
arr[1, 0] = 0.80;
arr[1, 1] = 1;
label1.Text =
arr[comboBox1.SelectedIndex,
comboBox2.SelectedIndex].ToString();//Index was outside the bounds of the array.
}
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
double[,] arr = new double[2, 2];
for(int i = 0; i < 2; i++)
{
arr[0, 0] = 1;
arr[0, 1] = 1.24;
arr[1, 0] = 0.80;
arr[1, 1] = 1;
label1.Text =
arr[comboBox1.SelectedIndex,
comboBox2.SelectedIndex].ToString();//Index was outside the bounds of the array.
}
}