Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#-当我在运行程序时添加一个数字时,出现以下错误';System.ArgumentOutOfRangeException';发生在mscorlib.dll中;_C#_Visual Studio - Fatal编程技术网

C#-当我在运行程序时添加一个数字时,出现以下错误';System.ArgumentOutOfRangeException';发生在mscorlib.dll中;

C#-当我在运行程序时添加一个数字时,出现以下错误';System.ArgumentOutOfRangeException';发生在mscorlib.dll中;,c#,visual-studio,C#,Visual Studio,因此,我试图在我的程序中填充课程,当我单击输入按钮而不是继续下一个学生时,我得到了以下错误:“mscorlib.dll中发生了类型为'System.ArgumentOutOfRangeException'的未处理异常” 这是按钮 命名空间WpfApplication1{ 公共部分类主窗口:窗口{ List<Students> student = new List<Students>(); int positionIndex = 0; public

因此,我试图在我的程序中填充课程,当我单击输入按钮而不是继续下一个学生时,我得到了以下错误:“mscorlib.dll中发生了类型为'System.ArgumentOutOfRangeException'的未处理异常”

这是按钮

命名空间WpfApplication1{ 公共部分类主窗口:窗口{

    List<Students> student = new List<Students>();
    int positionIndex = 0;

    public MainWindow() {

        InitializeComponent();     
    }

    void btnExe_Click(object sender, RoutedEventArgs e) {
        var course1 = Convert.ToDouble(txtCourse1.Text);
        var course2 = Convert.ToDouble(txtCourse2.Text);
        var course3 = Convert.ToDouble(txtCourse3.Text);
        student[positionIndex].c1 = course1;
        student[positionIndex].c2 = course2;
        student[positionIndex].c3 = course3;

        student[positionIndex].Name = positionIndex;
        stdNames.Text = student[positionIndex].Name.ToString();
        positionIndex++;
        if (positionIndex == 6) {
            btnExe.IsEnabled = false;
            calculate();
        };
    }
}



提前感谢,我真的无法找出问题所在。

在访问项目之前创建一个实例。
student.Add(newstudents());


你从来没有在
学生
列表中添加任何内容,所以它是空的,因此索引0中没有任何内容。你们真是太快了
public class Students {
    public int Name { get; set; }
    public double c1 { get ; set; }
    public double c2 { get; set; }
    public double c3 { get; set; }
}
void btnExe_Click(object sender, RoutedEventArgs e) {
        var course1 = Convert.ToDouble(txtCourse1.Text);
        var course2 = Convert.ToDouble(txtCourse2.Text);
        var course3 = Convert.ToDouble(txtCourse3.Text);
        student.Add(new Students());

        student[positionIndex].c1 = course1;
        student[positionIndex].c2 = course2;
        student[positionIndex].c3 = course3;

        student[positionIndex].Name = positionIndex;
        stdNames.Text = student[positionIndex].Name.ToString();
        positionIndex++;
        if (positionIndex == 6) {
            btnExe.IsEnabled = false;
            calculate();
        };
    }