我做了一類學生有一個參數課程和成績,這是數組,但當我嘗試添加一個學生,它不允許我輸入數組中的細節我只麪包車只輸入一個詞或數字我不能添加信息作爲一個數組在我的班學生
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
非常感謝。你真的很有幫助:) –