Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有这样的代码:
var result = list3.Where(Srodek => list4.Any(x => x == Srodek.Srodek.category1)).ToList();
并且我希望能够获得满足此子句的每一行的索引。我该怎么做?可能吗?List3 是我的主要列表。
Select具有接受谓词的签名,该谓词将项目及其索引作为输入参数。您可以在过滤列表之前使用它来保存索引:
Select
var result = list3 .Select((srodek, index) => new { Index = index, Match = list4.Any(x => x == srodek.Srodek.category1) }) .Where(x => x.Match) .Select(x => x.Index) .ToList();