Skip to content
CShift0.32

Array<T>

Struct · built-in type

struct Array<T>

An array, T[]: a fixed number of values, created with new T[n] (zeroed) or new T[] { a, b } / [a, b].

var squares = new int[10];
for (var i = 0; i < squares.Length; i += 1)
squares[i] = i * i;
foreach (var s in squares[1..4]) // a Slice<int>: 1, 4, 9
Console.WriteLine(s);

Arrays have reference semantics: assigning one shares the elements (reference counted); Array.Clone copies. a[i] checks the index (a panic outside of 0 to Length - 1), a[^1] is the last element, a[i..j] a Slice (a view). A List grows; an array does not.

Name Description
Length The number of elements.
int Length

The number of elements.

Name Description
Copy Copies count elements of source from sourceIndex to destination from destinationIndex (the ranges may overlap).
static void Copy(T[] source, int sourceIndex, T[] destination, int destinationIndex, int count)

Copies count elements of source from sourceIndex to destination from destinationIndex (the ranges may overlap).

Panics when a range is not inside of its array.

Name Description
Clone A copy of the array (new storage with the same elements).
T[] Clone()

A copy of the array (new storage with the same elements).