Arrays
In this page:
Arrays
An array is a fixed-size, ordered collection of elements of the same type, indexed starting at 0. Once created, its length cannot change. Arrays are the most basic collection type and back many of the more flexible collections internally.
Warning: Accessing an index outside the array's bounds throws an IndexOutOfRangeException at runtime.
Example: Arrays
using System;
class Program
{
static void Main(string[] args)
{
int[] numbers = { 10, 20, 30, 40 };
Console.WriteLine(numbers.Length);
Console.WriteLine(numbers[0]);
numbers[1] = 99;
foreach (int n in numbers)
{
Console.WriteLine(n);
}
}
}
Login to try C/C++/Java/PHP code in the editor
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: