如何确定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)
您需要将第一个列表与其他列表进行比较,您可以使用SequenceEqual:
List<int> first = yourLists[0];
bool allEqual = yourLists.Skip(1).All(l => first.SequenceEqual(l));
Run Code Online (Sandbox Code Playgroud)
由于在第一个不相等的列表上All返回false,这非常有效.