我试图创建一个名为Student
的类,其中包含成员名称,GPA和一个名为CourseRecord
的对象数组。我完全迷失在这里,因为我无法在我的课程中使用for循环或while循环来初始化CourseRecord
对象。这是我想使用的代码,但我不能使用for循环:使用从xml文档读取的对象数组创建类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Register
{
class StudentRecord
{
public string studentName;
public double studentGPA;
public CourseRecord[] grades = new CourseRecord[4];
public StudentRecord()
{
}
public StudentRecord(string name, double GPA)
{
studentName = name;
studentGPA = GPA;
}
for (int i = 0; i < CourseRecord.Length; i++;)
{
CourseRecord[i] = new CourseRecord;
CourseRecord[i].Read;
}
}
}
当你说你不能使用for循环时,你的意思是赋值有一条规则说你不能使用for循环吗? – DWright
Microsoft Visual Studio在类,结构或接口成员声明中给我提供错误“无效标记”。 –
这与您在问题标题中提及的阅读xml有什么关系?我完全不清楚自己想要达到的目标或卡在哪里。 “我完全迷失在这里”不是一个好问题。请参阅[如何提出一个好问题?](http://stackoverflow.com/help/how-to-ask),更具体地说[如何创建一个最小,完整和可验证的示例](http:/ /stackoverflow.com/help/mcve)。然后[编辑]你的问题,并具体说明你想要达到的目标,你认为你可以遵循什么方法,以及你卡在哪里。 – Alex