小编Aks*_*nde的帖子

合并两个字典并删除重复的键并按值排序

我必须将两个字典合并到一个字典中,删除重复的条目,并添加(如果第一个字典中不存在)。

 Dictionary<int, string> firstDict = new Dictionary<int, string>();
 firstDict.Add(1, "X");
 firstDict.Add(2, "B");

 Dictionary<int, string> secondDict = new Dictionary<int, string>();
 secondDict.Add(1, "M");
 secondDict.Add(4, "A");
Run Code Online (Sandbox Code Playgroud)

结果应该是这样的:

{4, "A"}
{2, "B"}
{1, "X"}
Run Code Online (Sandbox Code Playgroud)

c# dictionary

5
推荐指数
1
解决办法
4479
查看次数

标签 统计

c# ×1

dictionary ×1