Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C#

Nicholas Wallen
Nicholas Wallen
12,278 Points

What is an Index? And what is an item?

In the Index Out Of Range video, for C# Objects, they are referring to Indexes in Arrays. What does that mean, explain like I am five.

He also talks about different "items". Does he mean objects, like...explain lol

1 Answer

Steven Parker
Steven Parker
231,172 Points

An array contains a number of items.

Let's say you have this array:

string[] myArray = { "apple", "orange", "banana" };

This array has 3 items. Each "item" is a thing in the array, and in this case they are strings.

Now the index is a number indicating the position each item has in the array. When you refer to a specific item in an array, you put the index in brackets after the array name. These index numbers start at 0, so we would say the item at index 2 ("myArray[2]") is the string "banana". Unless we make the array bigger, that's the last item. And the first item is the one at index 0 ("myArray[0]") which is the string "apple".

Does that clear it up?