Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
This question was closed Nov 06, 2015 at 09:49 PM by Cripstat for the following reason:

The question is answered, right answer was accepted

avatar image
1
Question by Cripstat · Nov 06, 2015 at 09:46 PM · errorerror messagearraysarraylistremoveat

C# ArrayList Accessing and RemoveAt?

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?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Cripstat · Nov 06, 2015 at 09:48 PM 0
Share

Ok for anyone interested I worked it out on my own you can use .ReomveRange(index, count); index is the point which it begins removing from and count is the number of elements it will remove, it seems to work perfectly!

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

NullReferenceException: Object reference not set to an instance of an object 1 Answer

StackOverflowException, cant find out how to fix it 0 Answers

Getting errors in the console at the start of every project,Getting errors at the start of every porject 0 Answers

2D Sprite Package has a compile error that doesn't go away. How does one get rid of it? 0 Answers

Getting error on lap counter script JS 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges