我有这个和所有似乎工作正常,但不知道为什么,如果它的有效。C# - 从while循环中的词典中删除项目
Dictionary<string, List<string>> test = new Dictionary<string, List<string>>();
while (test.Count > 0)
{
var obj = test.Last();
MyMethod(obj);
test.Remove(obj.Key);
}
更新:谢谢你的答案,我已经更新了我的代码来解释为什么我不这样做Dictionary.Clear();