Linq,确定列表是否等于

Bob*_*obi -1 c# linq

如何确定a List<List<int>>中的项是否等于?

List<List<int>> equals = new List<List<int>>()
{
    new List<int>() { 1,2 },
    new List<int>() { 1,2 }
};

List<List<int>> notEquals = new List<List<int>>()
{
    new List<int>() { 1,2 },
    new List<int>() { 2,500}
};
Run Code Online (Sandbox Code Playgroud)

Tim*_*ter 5

您需要将第一个列表与其他列表进行比较,您可以使用SequenceEqual:

List<int> first = yourLists[0];
bool allEqual = yourLists.Skip(1).All(l => first.SequenceEqual(l));
Run Code Online (Sandbox Code Playgroud)

由于在第一个不相等的列表上All返回false,这非常有效.