c# - 更改/修改现有 keyValuePair 中的数据

标签 c# linq generics

我有这个

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/

相关文章:

c# - 如何动态生成必须放置在动态生成的组框内的切换按钮

c# - 聚合根。兔子洞有多远

c# - 下一个或上一个枚举

wcf - 动态构建ChannelFactory

java - 什么是原始类型,为什么我们不应该使用它呢?

c# - 你如何摆脱 C# 中的对象

linq - LINQ Lambda-在一个列表中查找所有ID,而在另一个列表中不存在

vb.net - 带有 Linq 语句的 XML 文字

c# - IEnumerable<IEnumerable<int>> - 没有重复的 IEnumerable<int>

c# - 在接口(interface)中使用泛型