C# TutorialLesson 20Free preview
C# Arrays
This lesson is part of C# · All levels
Summary
The array stores many values of the same type within one variable, with indexes starting at 0. The size of the array is determined when it is created and is unchanged, so its length can be viewed through the Length property. The array can be filled simultaneously with curly braces or tracked using foreach.
Key points
- General declaration: int[] number = {1, 2, 3} or new int[5] with index 0 to Length reduced by 1.
- All array elements must be of the same type.
- The length property returns the number of elements of an array.
- Access to an index outside the range triggers IndexOutOfRangeException.
- Two-dimensional arrays are created with new int[3, 4] and are accessed using arr[i, j].
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.