更新时间:2022-11-27 22:39:38
首先,使用SelectMany
展平列表,然后使用FirstOrDefault
进行过滤:
First, use SelectMany
to flatten the list, then FirstOrDefault
to filter:
CountryList.SelectMany(c => c.stateList).FirstOrDefault(d => d.Name == passedInValue);
请注意,由于FirstOrDefault
可以使用谓词,因此实际上不需要Where
子句.
Note that because FirstOrDefault
can take a predicate, you don't actually need the Where
clause.