• 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 /
avatar image
0
Question by TurboHermit · Aug 06, 2012 at 11:39 AM · arraylistindexfor

For all elements above a certain index

I'm trying to access all objects in a List above a certain index. The index I want is just a variable I have laying around, but I don't have a clear understanding of the For statement yet. I mean, I'm perfectly able to access ALL elements or elements that need a specific requirement too, but how can I access only the elements in the array above or beneath a certain index number?

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Akill · Aug 06, 2012 at 12:49 PM

You say you can access all elements , so I assume you have seen this before :

 for(int index=0;index < array.length;index++)
 {
 }

What this loop does is start at index =0 and keep incrementing index each time the for() statement is called (index++)..it will do this until index == array.length -1.

Now, you say you want to access all objects above a certain index, well, simply initialising the index variable to the index you want to start will work. So, instead of starting at index = 0 and looping through the entire array, you can start at say, index = 10 and then loop.

Clearly you will have to choose an index that IS less than array.length.

Comment
Add comment · Show 1 · Share
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 TurboHermit · Aug 06, 2012 at 01:26 PM 0
Share

Perfect, I already did this before, but apparently I make some kind of mistake along the way. Thanks for reassuring me! Helped me out alot!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I find a local variables index in a foreach loop? 1 Answer

Generic list of objects, then distance to those objects? (js) 1 Answer

A node in a childnode? 1 Answer

How do I check a List[0], when it's nothing? 1 Answer

Find specific element when duplicates exist in list. 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges