需要为以下对象添加值。应该可以添加student
subjects
列表。
创建了两个university
个对象,这些对象属于list类型,然后尝试添加值
public class university
{
public int student;
public IList<subject> subjects;
}
public class subject
{
public string text;
public int id;
};
最佳方法是什么
答案 0 :(得分:-2)
这可能会对你有帮助。
class Program
{
static void Main(string[] args)
{
var university = new University()
{
Student = 1,
Subjects = new List<Subject>()
{
new Subject() { Id = 1, Text = "Math" },
new Subject() { Id = 2, Text = "English" },
},
};
}
}
public class University
{
public int Student { get; set; }
public List<Subject> Subjects { get; set; } = new List<Subject>();
}
public class Subject
{
public int Id { get; set; }
public string Text { get; set; }
};