美文网首页
c# 查找Dictionary中相同值的键

c# 查找Dictionary中相同值的键

作者: 菜鸟的笔记 | 来源:发表于2021-03-01 17:29 被阅读0次
    #region MyRegion
    Dictionary<int, int> dict = new Dictionary<int, int>();

    public void Test()
    {
        dict.Add(1, 11);
        dict.Add(2, 11);
        dict.Add(3, 11);
        dict.Add(4, 112);
        dict.Add(5, 113);

        var list = dict.GroupBy(kvp => kvp.Value).ToList();

        foreach (var item in list)
        {
            //Debug.Log("相同的值 == " + item.Key);
            foreach (var subitem in item)
            {
                Debug.Log("相同的值 Value == " + item.Key+"   相同值对应的键 key == " + subitem.Key);
            }
        }
    }
    #endregion

打印日志

image.png

相关文章

网友评论

      本文标题:c# 查找Dictionary中相同值的键

      本文链接:https://www.haomeiwen.com/subject/aobafltx.html