将<int,string>和<int,double>合并到<double,string> C#字典中

use*_*156 2 c# merge dictionary

如果我的字典1是:

0 : string1
1 : string2
2 : string3
Run Code Online (Sandbox Code Playgroud)

而我的字典2是:

0 : 28.0
1 : 12.6
2 : -12.4
Run Code Online (Sandbox Code Playgroud)

如何获得组合字典:

28.0  : string1
12.6  : string2
-12.4 : string3
Run Code Online (Sandbox Code Playgroud)

这就是我到目前为止使用它们的方式

SortedDictionary<int, double> map2 = new SortedDictionary<int, double>();
SortedDictionary<int, string> map1 = new SortedDictionary<int, string>();
Run Code Online (Sandbox Code Playgroud)

编辑 - 对于这个问题,假设两个词典中的键都是连续的,并且按顺序递增并始终相同.

Sel*_*enç 8

假设两个字典具有相同的计数并具有相同的键:

map1.ToDictionary(x => map2[x.Key], x => x.Value)
Run Code Online (Sandbox Code Playgroud)

如果第二个字典具有重复值,则会失败.