初始化包含嵌套集合的集合

如何基于下面显示的类初始化’Quote’对象的集合,其中’Quote’将包含至少5’Rate’对象的集合。

List quotes = new List {new Quote { Id = 1, (need 5 Rate objects in here) } } public class Quote { public int Id { get; set; } public List Rates { get; set; } } public class Rate { public int Id { get; set; } public string AccommodationType { get; set; } public decimal Price { get; set; } } 

 List quotes = new List { new Quote { Id = 1, Rates = new List { new Rate { Id = 1, ...}, new Rate { Id = 2, ...}, ... } }, ... }; 

使用工厂方法为您创建此类对象图。

 List quotes = new List { new Quote { Id = 1, Rates = new List { new Rate { Id = 1, AccommodationType = "Whatever", Price = 0m }, new Rate { ...... } } } };