📜  unity dictionary foreach 删除 - C# 代码示例

📅  最后修改于: 2022-03-11 14:49:06.428000             🧑  作者: Mango

代码示例1
One of the restrictions of a foreach loop is that you can't change the underlying thing you're iterating over. 
If you change a dictionary while you're iterating through it, the program has no idea if it's getting out of sync and could end up for instance in an infinite loop.

Instead, you can get a list of the keys in the dictionary and iterate over that list. 
Since you won't be changing that list, just using it to change the dictionary, there's no chance of getting out of sync.