本文介绍了C# 从 List<List<int>> 中删除重复项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!
问题描述
例如,我无法想出最有效的算法来从 List<List<int>>
中删除重复项(我知道这看起来像 int 的列表[]
,但只是出于视觉目的这样做:
I'm having trouble coming up with the most efficient algorithm to remove duplicates from List<List<int>>
, for example (I know this looks like a list of int[]
, but just doing it that way for visual purposes:
所以输出就是
如果您有任何想法,请告诉我.我真的很感激.
Let me know if you have any ideas. I would really appreciate it.
推荐答案
自定义EqualityComparer
:>
然后您可以通过使用 Distinct 和自定义比较器来获得结果方法:
Then you can get the result by using Distinct with custom comparer method:
将索引包含在方法GetHashCode
中以确保不同的顺序不相等
Include the index into method GetHashCode
to make sure different orders will not be equal
这篇关于C# 从 List<List<int>> 中删除重复项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!
本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!