<tfoot id='7sN9u'></tfoot>
      <legend id='7sN9u'><style id='7sN9u'><dir id='7sN9u'><q id='7sN9u'></q></dir></style></legend>
    1. <i id='7sN9u'><tr id='7sN9u'><dt id='7sN9u'><q id='7sN9u'><span id='7sN9u'><b id='7sN9u'><form id='7sN9u'><ins id='7sN9u'></ins><ul id='7sN9u'></ul><sub id='7sN9u'></sub></form><legend id='7sN9u'></legend><bdo id='7sN9u'><pre id='7sN9u'><center id='7sN9u'></center></pre></bdo></b><th id='7sN9u'></th></span></q></dt></tr></i><div id='7sN9u'><tfoot id='7sN9u'></tfoot><dl id='7sN9u'><fieldset id='7sN9u'></fieldset></dl></div>
    2. <small id='7sN9u'></small><noframes id='7sN9u'>

        <bdo id='7sN9u'></bdo><ul id='7sN9u'></ul>

        在 linq 中设置相等

        set equality in linq(在 linq 中设置相等)
      1. <i id='Jl7AF'><tr id='Jl7AF'><dt id='Jl7AF'><q id='Jl7AF'><span id='Jl7AF'><b id='Jl7AF'><form id='Jl7AF'><ins id='Jl7AF'></ins><ul id='Jl7AF'></ul><sub id='Jl7AF'></sub></form><legend id='Jl7AF'></legend><bdo id='Jl7AF'><pre id='Jl7AF'><center id='Jl7AF'></center></pre></bdo></b><th id='Jl7AF'></th></span></q></dt></tr></i><div id='Jl7AF'><tfoot id='Jl7AF'></tfoot><dl id='Jl7AF'><fieldset id='Jl7AF'></fieldset></dl></div>

        1. <tfoot id='Jl7AF'></tfoot>

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

            <legend id='Jl7AF'><style id='Jl7AF'><dir id='Jl7AF'><q id='Jl7AF'></q></dir></style></legend>
              <bdo id='Jl7AF'></bdo><ul id='Jl7AF'></ul>

                <tbody id='Jl7AF'></tbody>

                1. 本文介绍了在 linq 中设置相等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有两个列表 A 和 B(列表).如何以最便宜的方式确定它们是否相等?我可以写类似'(A减B)联合(B减A)=空集'或将它们连接在一起并计算元素数量,但它相当昂贵.有解决办法吗?

                  I have two lists A and B (List). How to determine if they are equal in the cheapest way? I can write something like '(A minus B) union (B minus A) = empty set' or join them together and count amount of elements, but it is rather expensive. Is there workaround?

                  推荐答案

                  嗯,这取决于你如何解释你的列表.

                  Well, that depends on how you interpret your lists.

                  如果您将它们视为元组(因此列表中元素的顺序很重要),那么您可以使用以下代码:

                  If you consider them as tuples (so the order of elements in lists matters), then you can go with this code:

                      public bool AreEqual<T>(IList<T> A, IList<T> B)
                      {
                          if (A.Count != B.Count)
                              return false;
                          for (int i = 0; i < A.Count; i++)
                              if (!A[i].Equals(B[i])) 
                                  return false;
                      }
                  

                  如果您将列表视为集合(因此元素的顺序无关紧要),那么...我猜您使用了错误的数据结构:

                  If you consider your lists as sets (so the order of elements doesn't matter), then... you are using the wrong data structures I guess:

                      public bool AreEqual<T>(IList<T> A, IList<T> B)
                      {
                          HashSet<T> setA = new HashSet<T>(A);
                          return setA.SetEquals(B);
                      }
                  

                  这篇关于在 linq 中设置相等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Adding and removing users from Active Directory groups in .NET(在 .NET 中的 Active Directory 组中添加和删除用户)
                  HashSet conversion to List(HashSet 转换为 List)
                  How to set timeout for webBrowser navigate event(如何为 webBrowser 导航事件设置超时)
                  Test whether two IEnumerablelt;Tgt; have the same values with the same frequencies(测试两个IEnumerablelt;Tgt;具有相同频率的相同值)
                  How do you determine if two HashSets are equal (by value, not by reference)?(您如何确定两个 HashSet 是否相等(按值,而不是按引用)?)
                  Shorthand Accessors and Mutators(速记访问器和突变器)
                2. <legend id='hgU7x'><style id='hgU7x'><dir id='hgU7x'><q id='hgU7x'></q></dir></style></legend>

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

                  • <tfoot id='hgU7x'></tfoot>

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

                              <tbody id='hgU7x'></tbody>

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