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

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

      1. 您如何获得 ToDictionary() 失败的重复键?

        时间:2023-08-28
      2. <legend id='S5Cj2'><style id='S5Cj2'><dir id='S5Cj2'><q id='S5Cj2'></q></dir></style></legend>

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

                  <tbody id='S5Cj2'></tbody>

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

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

                  本文介绍了您如何获得 ToDictionary() 失败的重复键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在创建一个 Dictionary 对象,使用 IEnumerableToDictionary() 扩展方法:

                  I'm creating a Dictionary object, using IEnumerable's ToDictionary() extension method:

                  var dictionary = new Dictionary<string, MyType>
                      (myCollection.ToDictionary<MyType, string>(k => k.Key));
                  

                  当它执行时,它会抛出以下ArgumentException:

                  When it executes, it throws the following ArgumentException:

                  已添加具有相同密钥的项目.

                  An item with the same key has already been added.

                  如何让它告诉我重复键是什么?

                  How do I get it to tell me what the duplicate key is?

                  推荐答案

                  获取重复键:

                  var duplicateKeys =
                    myCollection
                   .GroupBy(k => k.Key)
                   .Where(g => g.Count() > 1)
                   .Select(g => g.Key);
                  

                  这篇关于您如何获得 ToDictionary() 失败的重复键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:C# - 合并两个重复行的数据表 下一篇:如何在保留重复项的同时进行整数列表交集?

                  相关文章

                  最新文章

                  <tfoot id='sDpsQ'></tfoot>

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

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

                    • <bdo id='sDpsQ'></bdo><ul id='sDpsQ'></ul>
                    1. <legend id='sDpsQ'><style id='sDpsQ'><dir id='sDpsQ'><q id='sDpsQ'></q></dir></style></legend>