所以我有这个班级的公共财产:
public static class DataStore
{
public static readonly List<Item> Items;
static DataStore
{
Items = new List<Item>
{
new Item {Name = "A"},
new Item {Name = "B"},
new Item {Name = "C"},
...//many more
};
}
}
为了提高内存效率,我在数据存储中添加了List<Lazy<Item>>
:
List<Lazy<Item>> LazyItems = new List<Lazy<Item>>
{
new Lazy<Item>(() => new Item {Name="A"}),
new Lazy<Item>(() => new Item {Name="B"}),
};
然而List<Item>
是一个公共财产,并在很多地方被引用。如何保留现有的List<Item>
并使用新属性?
答案 0 :(得分:1)
你做不到。 List<Item>
需要有一个完全具体化的已创建项目列表,因此,您需要已经创建了所有项目。您仍然无法创建一些项目,但不能创建所有项目,同时仍将其视为List<Item>
。