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.

Note

The index values of the individual ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.