我有這個和所有似乎工作正常,但不知道爲什麼,如果它的有效。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();