Answers for "unity c# loop dictionary and remove values"

C#
0

unity dictionary foreach remove

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.
Posted by: Guest on April-25-2020

Code answers related to "unity c# loop dictionary and remove values"

C# Answers by Framework

Browse Popular Code Answers by Language