使用SequenceEqual然后返回哪些元素不匹配

Jon*_*Jon 5 .net c# linq .net-4.0 c#-4.0

我有两个List<string>,我正在使用该SequenceEqual方法来确定它们是否匹配.

我现在需要获得List<int>, string, IEnumerable,失败的元素的任何索引.

有一个简单的方法吗?

谢谢

Ani*_*Ani 3

我想你想要:

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);
Run Code Online (Sandbox Code Playgroud)

请注意,如果其中一个列表比另一个列表长,则不会考虑超出较小列表长度的项目。