我有这个
foreach (KeyValuePair<string, Object> tempData in tempList.ToDictionary(x => x.Key, y => y.Value))
{
tempData["fahrzeugA"] = "s";
}
但是使用 tempData["fahrzeugA"] = "s";
将不起作用。
我得到:
Cannot apply indexing with [] to an expression of type 'System.Collections.Generic.KeyValuePair'
如果我有一个现有的键 fahrzeugA
,我想更改它,正确的语法是什么?
最佳答案
你可以应用这个:
var tempList = new List<Test>();
var dic = tempList.ToDictionary(x => x.Key, y => y.Value);
foreach (var tempData in dic)
{
dic[tempData.Key] = "s";
}
关于c# - 更改/修改现有 keyValuePair 中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36881573/