Struct ReadOnlyArray<TValue>
Read-only access to an array or to a slice of an array.
Namespace: UnityEngine.InputSystem.Utilities
Syntax
public struct ReadOnlyArray<TValue> : IReadOnlyList<TValue>, IReadOnlyCollection<TValue>, IEnumerable<TValue>, IEnumerable
Type Parameters
Name | Description |
---|---|
TValue | Type of values stored in the array. |
Remarks
The purpose of this struct is to allow exposing internal arrays directly such that no boxing and no going through interfaces is required but at the same time not allowing the internal arrays to be modified.
Constructors
ReadOnlyArray(TValue[])
Construct a read-only array covering all of the given array.
Declaration
public ReadOnlyArray(TValue[] array)
Parameters
Type | Name | Description |
---|---|---|
TValue[] | array | Array to index. |
ReadOnlyArray(TValue[], Int32, Int32)
Construct a read-only array that covers only the given slice of array
.
Declaration
public ReadOnlyArray(TValue[] array, int index, int length)
Parameters
Type | Name | Description |
---|---|---|
TValue[] | array | Array to index. |
System.Int32 | index | Index at which to start indexing |
System.Int32 | length | Length of the slice to index from |
Properties
Count
Number of elements in the array.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Item[Int32]
Return the element at the given index.
Declaration
public TValue this[int index] { get; }
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | Index into the array. |
Property Value
Type | Description |
---|---|
TValue |
Exceptions
Type | Condition |
---|---|
System.IndexOutOfRangeException |
|
System.InvalidOperationException |
Methods
GetEnumerator()
Declaration
public IEnumerator<TValue> GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerator<TValue> |
IndexOf(Predicate<TValue>)
Declaration
public int IndexOf(Predicate<TValue> predicate)
Parameters
Type | Name | Description |
---|---|---|
System.Predicate<TValue> | predicate |
Returns
Type | Description |
---|---|
System.Int32 |
ToArray()
Convert to array.
Declaration
public TValue[] ToArray()
Returns
Type | Description |
---|---|
TValue[] | A new array containing a copy of the contents of the read-only array. |
Operators
Implicit(TValue[] to ReadOnlyArray<TValue>)
Declaration
public static implicit operator ReadOnlyArray<TValue>(TValue[] array)
Parameters
Type | Name | Description |
---|---|---|
TValue[] | array |
Returns
Type | Description |
---|---|
ReadOnlyArray<TValue> |