我在另一个问题中发现了example。我想知道wat的目的是由Question()方法服务的。这似乎是当创建Question对象时,Answer属性被创建为Answer [s]的List对象。为什么在创建列表对象的模型中创建方法
这是我第一次看到这种技术,作为一名新程序员,这种模式有什么好处?
public class Question
{
public Question()
{
this.Answers = new List<Answer>();
}
public int QuestionId { get; set; }
public string Title { get; set; }
public virtual ICollection<Answer> Answers { get; set; }
}
public class Answer
{
public int AnswerId { get; set; }
public string Text { get; set; }
}