【发布时间】:2019-09-05 05:19:37
【问题描述】:
当我调试以下代码时,它总是抛出以下异常:
给定的键不在字典中。
我需要帮助解决这个问题。
string current;
Dictionary<string, List<int>> map = new Dictionary<string, List<int>>();
for (int i = 0; i < y; i++){
current = lines[i].material.Text + "," + lines[i].profilid.Text;
if (map[current] == null){
map[current] = new List<int>();
}
map[current].Add(i);
material_profile.Add(current);
}
foreach (KeyValuePair<string, List<int>> entry in map){
List<int> lenghts = new List<int>();
// do something with entry.Value or entry.Key
for (int i = 0; i < entry.Value.Count(); i++){
int stueckzahl = int.Parse(lines[entry.Value[i]].stueck.Text);
int laenge = int.Parse(lines[entry.Value[i]].länge.Text);
for (int j = 0; j < stueckzahl; j++){
lenghts.Add(laenge);
}
}
}
【问题讨论】:
标签: c# dictionary