【发布时间】:2014-08-10 03:19:52
【问题描述】:
在 C# 中,如果我有一个对象列表,其中每个列表都有一个列表项列表,并且这些列表项中的每一个都可以是一个对象列表(或只是一个列表项),那么最好的方法是什么?按名称检索特定列表?
每个列表和列表项都有一个唯一的名称。 MapLocationListItem 中的 type 属性是“List”或“ListItem”。
以下是课程:
public class MapLocationList
{
public string name { get; set; }
public List<MapLocationListItem> listItems { get; set;}
public MapLocationList ()
{
listItems = new List<MapLocationListItem> ();
}
}
public class MapLocationListItem
{
public string name { get; set;}
public string type { get; set;}
public string heading { get; set;}
public string subheading { get; set;}
MapLocationList mapLocationList{ get; set;}
}
提前致谢
【问题讨论】:
-
尝试使用 Linq 并指定需要查找的项目
-
你的模型对我来说有点奇怪,你的
MapLocationList有一个MapLocationListItem的列表,其中有一个MapLocationLists 的列表?
标签: c# list object search recursion