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

    2. <legend id='NS0m8'><style id='NS0m8'><dir id='NS0m8'><q id='NS0m8'></q></dir></style></legend>

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

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

        • <bdo id='NS0m8'></bdo><ul id='NS0m8'></ul>

      1. 在字典中查找重复值并打印重复元素的键

        时间:2023-08-27

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

          • <legend id='tnPHz'><style id='tnPHz'><dir id='tnPHz'><q id='tnPHz'></q></dir></style></legend><tfoot id='tnPHz'></tfoot>

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

                    <tbody id='tnPHz'></tbody>
                  本文介绍了在字典中查找重复值并打印重复元素的键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  检查字典中的重复值并打印其键的最快方法是什么?

                  What can be the fastest way to to check the duplicate values in the dictionary and print its key?

                  字典 MyDict 具有以下值,

                  关键价值

                  22 100

                  24 200

                  25 100

                  26 300

                  29 200

                  39 400

                  41 500

                  示例:键 22 和 25 具有相同的值,我需要打印 22 和 25 具有重复值.

                  Example: key 22 and 25 have same values and i need to print that 22 and 25 have duplicate values.

                  推荐答案

                  视情况而定.如果您有一本不断变化的字典,并且只需要获取一次该信息,请使用:

                  It depends. If you have an ever changing dictionary and need to get that information only once, use this:

                  MyDict.GroupBy(x => x.Value).Where(x => x.Count() > 1)
                  

                  但是,如果您的字典或多或少是静态的,并且需要多次获取此信息,则不应只将数据保存在字典中,还应将数据保存在 ILookup 中字典的值作为键,字典的键作为值:

                  However, if you have a dictionary that is more or less static and need to get this information more than once, you should not just save your data in a Dictionary but also in a ILookup with the value of the dictionary as the key and the key of the dictionary as the value:

                  var lookup = MyDict.ToLookup(x => x.Value, x => x.Key).Where(x => x.Count() > 1);
                  

                  要打印信息,您可以使用以下代码:

                  To print the info, you can use the following code:

                  foreach(var item in lookup)
                  {
                      var keys = item.Aggregate("", (s, v) => s+", "+v);
                      var message = "The following keys have the value " + item.Key + ":" + keys;
                      Console.WriteLine(message);
                  }
                  

                  这篇关于在字典中查找重复值并打印重复元素的键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:从文本文件中删除重复行? 下一篇:如何防止重复回发混淆我的业务层

                  相关文章

                  最新文章

                    <legend id='zSOHd'><style id='zSOHd'><dir id='zSOHd'><q id='zSOHd'></q></dir></style></legend>

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

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

                      <tfoot id='zSOHd'></tfoot>

                      • <bdo id='zSOHd'></bdo><ul id='zSOHd'></ul>