【发布时间】:2016-04-26 13:18:02
【问题描述】:
我读过那些文章:
First、second 和third 仅适用于删除项目的情况,但我不删除它们。
我的代码:
Dictionary<String, Object> tempList =(Dictionary<String,Object>)_ersetzeDasMitDas;
//pfadFuerDieBildDatei
foreach (KeyValuePair<string, Object> tempData in tempList)
{
if (tempData.Key.Equals("fahrzeugGruppe"))
{
if (tempData.Value!=null)
{
if (tempData.Value.Equals("LKW"))
{
tempList["pfadFuerDieBildDatei"]= Path.Combine(VirtualMachineKonstanten.statischeDateien, "lkw.png");
}
else if (tempData.Value.Equals("Transporter"))
{
tempList["pfadFuerDieBildDatei"]= Path.Combine(VirtualMachineKonstanten.statischeDateien, "transporter.png");
}
else
{
tempList["pfadFuerDieBildDatei"]= Path.Combine(VirtualMachineKonstanten.statischeDateien, "pkw.png");
}
}
else
{
//todo: logge Error "fahrzeugGruppe", der Wert ist null ?!
//erstmal für Testing
tempList["pfadFuerDieBildDatei"]= Path.Combine(VirtualMachineKonstanten.statischeDateien, "pkw.png");
}
}
}
我明白了:
集合已修改;枚举操作可能无法执行,
在写入tempList["pfadFuerDieBildDatei"] 并再次进入循环之后。
如何解决?
【问题讨论】:
-
IEnumerable<KeyValuePair<String, Object>> ErsetzeDasMitDas签名
标签: c# dictionary key-value