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.
Are there any code examples left?
New code examples in category C#
-
C# 2022-03-27 22:40:23 c# movement script
-
C# 2022-03-27 22:15:17 Delete last modification on EntityFramework Core
-
C# 2022-03-27 22:15:02 file.create folder c#
-
C# 2022-03-27 19:25:04 Error inflating class android.support.constraint.ConstraintLayout
-
C# 2022-03-27 19:15:02 top down shooting in unity 2D
-
C# 2022-03-27 18:50:02 c# remove invalid directory characters
-
C# 2022-03-27 18:30:07 how to use K2 games Games parallax background
-
C# 2022-03-27 18:25:10 c# replace crlf
-
C# 2022-03-27 18:25:09 keycode for left mouse click unity