我有一个包含另一个List<>的列表。
我需要查找给定值是否存在于最内层列表中的任何项目中。
如果找到匹配项,我需要返回该特定项。
我正在如下所示地执行此操作:
InnerList inner = null;
foreach(TopList in topListItems)
{
inner = asn.Owners.Find(x => x.GuestId == guestId);
if(inner != null)
break;
}
//item found if inner is not null
//else item absent in the inner list
Any other alternate way that may run faster than this?
编辑: 有所更正:我只需要查看内部列表是否具有特定值的项目。 如果是,则需要返回具有匹配项的顶级项目。 我想逻辑是相同的。
topList.FirstOrDefault(innerList => innerList.Any(item => item.GuestId == guestId)
。 - Clayton