私はパラメータのコースと成績配列を持っている学生のクラスを作ったが、学生を追加しようとすると配列のように詳細を入力することはできません私バンはただ一つの単語や数字私のクラスの学生の配列として情報を追加することはできません
Student s1 = new Student(dev, 1691676, "eng,maths", 50);
ここでは、あなたが配列、string[]
ではなく、単一string
を追加する必要があり、コード
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
ありがとうlot.its本当に有用な:) –