Getting and Setting Array Values

In this lesson you'll learn how to access and change array values.

Accessing Array Values #

We use indexing to access arrays values just like we did in the previous lesson.

Suppose you declared an array of 10 elements.

You can use the array members from arr[0] to arr[9].

Note: If you try to access array elements outside of its bound, let’s say arr[14], the compiler may throw an “System.IndexOutOfRangeException”.

Look at the example below for better understanding.

Get hands-on with 1400+ tech skills courses.