假设我有float[]
,其中数组中的每个位置都具有唯一含义。每个位置对应于以下字典中的条目,其中int
指的是数组偏移:
// The int below refers to a position within the float
Dictionary<myObjectDetail, int>
我想加入float[index_to_merge]
与Dictionary<myObjectDetail,index_to_merge>
,所以我最终会得到类似
Dictionary<myObjectDetail,floatvalue>
我可以使用Linq解决此问题,并将这些对象合并为一个新的匿名类型吗?
答案 0 :(得分:2)
您可以使用以下方法实现这一目标:
var newDictionary = oldDictionary.ToDictionary(x => x.Key, x => floats[x.Value]);
此处oldDictionary
是您的原始Dictionary<myObjectDetail, int>
,现在您的newDictionary
是Dictionary<myObjectDetail,floatvalue>
,这就是您想要的。