我有两个 List<string>
我正在使用 SequenceEqual
方法来确定它们是否匹配。
我现在需要一个 List<int>, string, IEnumerable,
失败的元素的任何索引。
有没有简单的方法?
谢谢
最佳答案
我想你想要:
List<string> list1 = ...
List<string> list2 = ...
var differentIndices = list1.Zip(list2, (item1, item2) => item1 == item2)
.Select((match, index) => new { Match = match, Index = index })
.Where(a => !a.Match)
.Select(a => a.Index);
请注意,如果其中一个列表比另一个长,则不会考虑超出较小列表长度的项目。
关于c# - 使用 SequenceEqual 然后返回哪些元素不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8342013/