我想在列表列表中使用Remove()方法,但它对我不起作用.
简单的例子应该说一切:
List<List<int>> list = new List<List<int>>();
list.Add(new List<int> { 0, 1, 2 });
list.Add(new List<int> { 1, 2 });
list.Add(new List<int> { 4 });
list.Add(new List<int> { 0, 1, });
list.Remove(new List<int> { 1, 2 });
Run Code Online (Sandbox Code Playgroud)
如果我使用RemoveAt(1)它工作正常但删除()没有.
显然,此代码返回false的原因相同:
List<int> l1 = new List<int>();
List<int> l2 = new List<int>();
l1.Add(1);
l2.Add(1);
bool b1 = l1 == l2; // returns False
bool b2 = l1.Equals(l2); // returns False too
Run Code Online (Sandbox Code Playgroud)
所以在我看来,我不能简单地比较两个列表甚至数组.我可以使用循环而不是Remove(),但必须有更简单的方法.
提前致谢.