1. <legend id='NZ5Wh'><style id='NZ5Wh'><dir id='NZ5Wh'><q id='NZ5Wh'></q></dir></style></legend>

      <small id='NZ5Wh'></small><noframes id='NZ5Wh'>

      <tfoot id='NZ5Wh'></tfoot>
      <i id='NZ5Wh'><tr id='NZ5Wh'><dt id='NZ5Wh'><q id='NZ5Wh'><span id='NZ5Wh'><b id='NZ5Wh'><form id='NZ5Wh'><ins id='NZ5Wh'></ins><ul id='NZ5Wh'></ul><sub id='NZ5Wh'></sub></form><legend id='NZ5Wh'></legend><bdo id='NZ5Wh'><pre id='NZ5Wh'><center id='NZ5Wh'></center></pre></bdo></b><th id='NZ5Wh'></th></span></q></dt></tr></i><div id='NZ5Wh'><tfoot id='NZ5Wh'></tfoot><dl id='NZ5Wh'><fieldset id='NZ5Wh'></fieldset></dl></div>

          <bdo id='NZ5Wh'></bdo><ul id='NZ5Wh'></ul>

        C# 从 List&lt;List&lt;int&gt;&gt; 中删除重

        时间:2023-08-27
          <tbody id='e9WmD'></tbody>
        1. <tfoot id='e9WmD'></tfoot>
          • <i id='e9WmD'><tr id='e9WmD'><dt id='e9WmD'><q id='e9WmD'><span id='e9WmD'><b id='e9WmD'><form id='e9WmD'><ins id='e9WmD'></ins><ul id='e9WmD'></ul><sub id='e9WmD'></sub></form><legend id='e9WmD'></legend><bdo id='e9WmD'><pre id='e9WmD'><center id='e9WmD'></center></pre></bdo></b><th id='e9WmD'></th></span></q></dt></tr></i><div id='e9WmD'><tfoot id='e9WmD'></tfoot><dl id='e9WmD'><fieldset id='e9WmD'></fieldset></dl></div>
            <legend id='e9WmD'><style id='e9WmD'><dir id='e9WmD'><q id='e9WmD'></q></dir></style></legend>

              1. <small id='e9WmD'></small><noframes id='e9WmD'>

                  <bdo id='e9WmD'></bdo><ul id='e9WmD'></ul>
                  本文介绍了C# 从 List&lt;List&lt;int&gt;&gt; 中删除重复项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  例如,我无法想出最有效的算法来从 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:

                  my_list[0]= {1, 2, 3};
                  my_list[1]= {1, 2, 3};
                  my_list[2]= {9, 10, 11};
                  my_list[3]= {1, 2, 3};
                  

                  所以输出就是

                  new_list[0]= {1, 2, 3};
                  new_list[1]= {9, 10, 11};
                  

                  如果您有任何想法,请告诉我.我真的很感激.

                  Let me know if you have any ideas. I would really appreciate it.

                  推荐答案

                  自定义EqualityComparer>:

                  public class CusComparer : IEqualityComparer<List<int>>
                  {
                      public bool Equals(List<int> x, List<int> y)
                      {
                          return x.SequenceEqual(y);
                      }
                  
                      public int GetHashCode(List<int> obj)
                      {
                          int hashCode = 0;
                  
                          for (var index = 0; index < obj.Count; index++)
                          {
                              hashCode ^= new {Index = index, Item = obj[index]}.GetHashCode();
                          }
                  
                          return hashCode;
                      }
                  }
                  

                  然后您可以通过使用 Distinct 和自定义比较器来获得结果方法:

                  Then you can get the result by using Distinct with custom comparer method:

                  var result = my_list.Distinct(new CusComparer());
                  

                  将索引包含在方法GetHashCode中以确保不同的顺序不相等

                  Include the index into method GetHashCode to make sure different orders will not be equal

                  这篇关于C# 从 List&lt;List&lt;int&gt;&gt; 中删除重复项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:使用 LINQ 跨多个属性查找重复项 下一篇:在 C# List 中查找重复项索引的最优雅方法是什么

                  相关文章

                  最新文章

                  <small id='19U4w'></small><noframes id='19U4w'>

                  <i id='19U4w'><tr id='19U4w'><dt id='19U4w'><q id='19U4w'><span id='19U4w'><b id='19U4w'><form id='19U4w'><ins id='19U4w'></ins><ul id='19U4w'></ul><sub id='19U4w'></sub></form><legend id='19U4w'></legend><bdo id='19U4w'><pre id='19U4w'><center id='19U4w'></center></pre></bdo></b><th id='19U4w'></th></span></q></dt></tr></i><div id='19U4w'><tfoot id='19U4w'></tfoot><dl id='19U4w'><fieldset id='19U4w'></fieldset></dl></div>

                    <bdo id='19U4w'></bdo><ul id='19U4w'></ul>
                • <tfoot id='19U4w'></tfoot>
                    <legend id='19U4w'><style id='19U4w'><dir id='19U4w'><q id='19U4w'></q></dir></style></legend>