我已经初始化了一个二维数组,并从索引 5 开始包含空值。我正在尝试将数组值添加到我的图表控件中。当我尝试将值显示到 Console.WriteLine 时,没有发生异常,但是当我添加到我的图表系列时,异常是“索引超出了数组的范围”。任何人都可以帮助我吗?是因为图表控件的柱线有限吗?
try
{
//females age range
string[,] gAge = new string[10, 2];
gAge[0, 0] = "F.13-17";
gAge[0, 1] = yf.f1317.ToString();
gAge[1, 0] = "F.18-24";
gAge[1, 1] = yf.f1824.ToString();
gAge[2, 0] = "M.25-34";
gAge[2, 1] = yf.m2534.ToString();
gAge[3, 0] = "M.13-17";
gAge[3, 1] = yf.m1317.ToString();
gAge[4, 0] = "M.18-24";
gAge[4, 1] = yf.m1824.ToString();
for (int i = 0; i < gAge.Length; i++)
{
if (gAge[i, 0] == null)
{
break;
}
else
{
Console.WriteLine(gAge[i, 0].ToString());
string[] seriesArray = { gAge[i, 0].ToString() };
Series series = this.chart1.Series.Add(seriesArray[i]);
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}