Accessing Individual Array Elements

An individual array element is accessed in the same manner as an individual character of a string variable—by writing the array variable name followed by a pair of square brackets containing the index value of the element. The following line

accountBalances[0] = 1000m;

assigns the value 1000 of type decimal to the first element of array elements contained in the object referenced by accountBalances. The index can be any numerical expression with a non-negative value of a type implicitly convertible to type int, and must be evaluated to a value less than the length of the array.


The index values of the individual ...

Get C# Primer Plus now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.