我做了一类学生有一个参数课程和成绩,这是数组,但当我尝试添加一个学生,它不允许我输入数组中的细节我只面包车只输入一个词或数字我不能添加信息作为一个数组在我的班学生
Student s1 = new Student(dev, 1691676, "eng,maths", 50);
这里是代码
public class Student
{
public string name;
public int studentId;
public string[] courses;
public int[] grades ;
public Student(string name,int studentId,string[] courses,int[] grades)
{
this.name = name;
this.studentId = studentId;
this.courses = courses;
this.grades = grades;
}
public void info()
{
Console.WriteLine("name of the student is" + name);
Console.WriteLine("StudentID of the student is" + studentId);
Console.WriteLine("courses taken by student are" + courses);
Console.WriteLine("grades earned by the student are" + grades);
}
public void sleep()
{
Console.WriteLine("enter the amount of time the student slept");
int sleep=Convert.ToInt32(Console.ReadLine());
int a = grades.Length;
int b = 0;
if (b<a)
{
grades[b] = grades[b] - (sleep/10);
}
}
}
我想你可能想阅读约占阵列如何工作。请参阅:https://msdn.microsoft.com/en-us/library/aa288453(v=vs.71).aspx – aquinas
非常感谢。你真的很有帮助:) –