【发布时间】:2016-04-27 06:06:41
【问题描述】:
我有这个
foreach (KeyValuePair<string, Object> tempData in tempList.ToDictionary(x => x.Key, y => y.Value))
{
tempData["fahrzeugA"] = "s";
}
但是使用tempData["fahrzeugA"] = "s"; 将不起作用。
我明白了:
无法将 [] 索引应用于类型表达式 'System.Collections.Generic.KeyValuePair'
如果我有一个想要更改的现有密钥 fahrzeugA,正确的语法是什么?
【问题讨论】:
-
ToDictionary返回一个新对象。您不能以这种方式修改 tempList。 -
tempList中存储的类型是什么?键值对? -
你想做什么?更改
tempList中具有“fahrzeugA”键的项目?