我正试图List<int>
从a中删除a List<List<int>>
,我到处寻找并且没有找到解决方案.
这是我到目前为止所尝试的:
List<List<int>> my2DList = ... ; // this is where I assign my 2D list
my2DList.Remove(new List<int>( ... ));
Run Code Online (Sandbox Code Playgroud)
但是my2DList
长度保持不变.我该怎么办?
问题是List<int>
不会覆盖Equals
/ GetHashCode
,因此您的新列表永远不会等于现有列表.(基本上,它将比较参考而不是内容.)
三种选择:
Remove
RemoveAt
RemoveAll
最后一个例子:
List<int> listToRemove = new List<int> { ... };
my2DList.RemoveAll(x => x.SequenceEqual(listToRemove));
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
69 次 |
最近记录: |