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.
Fields
Section titled “Fields”| Name | Description |
|---|---|
Length |
The number of elements. |
Length
Section titled “Length”int LengthThe number of elements.
Static methods
Section titled “Static methods”| 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.
Methods
Section titled “Methods”| 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).