给定一些字典
Dictionary<string, string> GroupNames = new Dictionary<string, string>();
Dictionary<string, string> AddedGroupNames = new Dictionary<string, string>();
我无法将它们合并为一个:
GroupNames = GroupNames.Concat(AddedGroupNames);
因为“类型不能隐式转换”。我相信(我的代码证明我是对的)它们的类型是相同的 - 我忽略了什么?
我认为你定义了你的GroupNames
as Dictionary<string,string>
,所以你需要添加ToDictionary
像这样:
GroupNames = GroupNames.Concat(AddedGroupNames)
.ToDictionary(x=>x.Key,x=>x.Value);
请注意,两个原始字典将具有不同的键,否则我们需要一些规则来正确合并它们。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)