Start learning free

LESSON 103 OF 674 · ARRAYS I

Accessing List elements in C#

Lesson

We can access the data inside a List using indexes and the [] operator, just like with arrays.

Lists also use zero-based indexing, so the first element in a List has an index of 0.

List<int> numbers = new List<int> {50, 60, 70};

Console.WriteLine(numbers[0]); // Output: 50

int data = numbers[1];
Console.WriteLine(data); // Output: 60

Assignment
Follow the Coding Tutorial and let's play with some lists.


Hint
Look at the examples above if you get stuck.


STEP 1 OF 3
    Ctrl + Enter to check