Quantcast
Channel: Questions in topic: "error"
Viewing all articles
Browse latest Browse all 7934

C# ArrayList Accessing and RemoveAt?

$
0
0
So I have an ArrayList defined and I'm feeding it information, once it hits 5 units large I want it to delete everything past the first position in the array I.e if the array contains [0,3,2,1,4] I want to kill everything that isn't 0. To do this I am using the `.RemoveAt(i);` function and it works to an extent as I can remove say 0,1,2 but when I try to use the third and fourth positions as i I get the error "Index is less than 0 or more than or equal to the list count" I assume this has something to do with the fact the position of the other elements changes as I delete one but I can't work out the solution. The aim is to remove all units except the first one so the Array List can exist. if (spellInput.Count == 5) { Debug.Log("STORE!"); spellInput.RemoveAt(0); spellInput.RemoveAt(1); spellInput.RemoveAt(2); spellInput.RemoveAt(3); Debug.Log(spellInput.Count); } Any ideas?

Viewing all articles
Browse latest Browse all 7934

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>