我现在正在学习面向对象编程,但我在练习中遇到了问题。我有一个有学生的学校班级。同一班级的学生人数不得相同。我有以下内容:
class SchoolClass
{
private List<Student> students;
public List<Student> Students
{
get { return this.students; }
set
{
if (value == null) throw new ArgumentNullException("Students list can not be null!");
if (value.Select(n => n.Number).Distinct().Count() != value.Count())
throw new ArgumentException("There are students in the list with the same class number!");
this.students = value;
}
}
public SchoolClass( List<Student> students)
{
this.Students = students;
}
}
class Student
{
private uint number;
public uint Number
{
get { return this.number; }
set …Run Code Online (Sandbox Code Playgroud)