我試圖讓反對時刻電荷之間的圖表,我得到這個錯誤:指數在圖形數組的範圍之外繪製C#
Index was outside the bounds of array
我的代碼如下:
namespace WindowsFormsApplication19
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
double max = 24000000, min = 23999999.85;
double[] q = new double[9];
int t = 0;
for (t = 1; t <= 10; t++)
{
q[t] = (24 * Math.Pow(10, 6)) * Math.Exp(-t/(2000 * Math.Pow(10, 6)));
chart1.Series[0].Points.AddXY(t, q[t]);
}
chart1.ChartAreas[0].AxisY.Maximum = max;
chart1.ChartAreas[0].AxisY.Minimum = min;
chart1.Series[0].ChartType = SeriesChartType.FastLine;
chart1.Series[0].Color = Color.Red;
}
}
}
我試過,但我仍然有同樣的問題:
private void button1_Click(object sender, EventArgs e) {
double[] q = new double[9];
int t = 0;
for (int i = 0; i <= 9; i++)
{
for (t = 1; t <= 10; i++)
{
q[i] = (24 * Math.Pow(10, 6)) * Math.Exp(-t/(2000 * Math.Pow(10, 6)));
chart1.Series[0].Points.AddXY(t, q[i]);
}
}
}
陣列索引0爲主。從0開始到8.注意'q'長度9.所以,你應該從0到8不爲1〜10 –