Class DynamicArray<T>
Generic growable array.
Inherited Members
Namespace: UnityEngine.Rendering
Assembly: Unity.RenderPipelines.Core.Runtime.dll
Syntax
public class DynamicArray<T> where T : new()
Type Parameters
Name | Description |
---|---|
T | Type of the array. |
Constructors
DynamicArray()
Constructor. Defaults to a size of 32 elements.
Declaration
public DynamicArray()
DynamicArray(int)
Constructor
Declaration
public DynamicArray(int size)
Parameters
Type | Name | Description |
---|---|---|
int | size | Number of elements. |
Properties
this[int]
ref access to an element.
Declaration
public ref T this[int index] { get; }
Parameters
Type | Name | Description |
---|---|---|
int | index | Element index |
Property Value
Type | Description |
---|---|
T | The requested element. |
capacity
Allocated size of the array.
Declaration
public int capacity { get; }
Property Value
Type | Description |
---|---|
int |
size
Number of elements in the array.
Declaration
public int size { get; }
Property Value
Type | Description |
---|---|
int |
Methods
Add(in T)
Add an element to the array.
Declaration
public int Add(in T value)
Parameters
Type | Name | Description |
---|---|---|
T | value | Element to add to the array. |
Returns
Type | Description |
---|---|
int | The index of the element. |
AddRange(DynamicArray<T>)
Adds the elements of the specified collection to the end of the DynamicArray.
Declaration
public void AddRange(DynamicArray<T> array)
Parameters
Type | Name | Description |
---|---|---|
DynamicArray<T> | array | The array whose elements should be added to the end of the DynamicArray. The array itself cannot be null, but it can contain elements that are null, if type T is a reference type. |
Clear()
Clear the array of all elements.
Declaration
public void Clear()
Contains(T)
Determines whether the DynamicArray contains a specific value.
Declaration
public bool Contains(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The object to locate in the DynamicArray. |
Returns
Type | Description |
---|---|
bool | true if item is found in the DynamicArray; otherwise, false. |
FindIndex(int, int, Predicate<T>)
Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the first occurrence within the range of elements in the DynamicArray that starts at the specified index and contains the specified number of elements.
Declaration
public int FindIndex(int startIndex, int count, Predicate<T> match)
Parameters
Type | Name | Description |
---|---|---|
int | startIndex | The zero-based starting index of the search. |
int | count | The number of elements in the section to search. |
Predicate<T> | match | The Predicate delegate that defines the conditions of the element to search for. |
Returns
Type | Description |
---|---|
int | The zero-based index of the first occurrence of an element that matches the conditions defined by match, if found; otherwise, -1. |
GetEnumerator()
Returns an enumerator that iterates through of this array. See the IEnumerable docs for more info: https://docs.microsoft.com/en-us/dotnet/api/system.collections.ienumerable
Declaration
public DynamicArray<T>.Iterator GetEnumerator()
Returns
Type | Description |
---|---|
DynamicArray<T>.Iterator | Iterator pointing before the first element in the array. |
Remarks
The returned struct intentionally does not explicitly implement the IEnumarable/IEnumerator interfaces it just follows
the same function signatures. This means the duck typing used by foreach
on the compiler level will
pick it up as IEnumerable but at the same time avoids generating Garbage.
For more info, see the C# language specification of the foreach
statement.
IndexOf(T)
Searches for the specified object and returns the zero-based index of the first occurrence within the entire DynamicArray.
Declaration
public int IndexOf(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The object to locate in the DynamicArray. The value can be null for reference types. |
Returns
Type | Description |
---|---|
int | he zero-based index of the first occurrence of item within the entire DynamicArray, if found; otherwise, -1. |
IndexOf(T, int)
Searches for the specified object and returns the zero-based index of the first occurrence within the range of elements in the DynamicArray that extends from the specified index to the last element.
Declaration
public int IndexOf(T item, int index)
Parameters
Type | Name | Description |
---|---|---|
T | item | The object to locate in the DynamicArray. The value can be null for reference types. |
int | index | The zero-based starting index of the search. 0 (zero) is valid in an empty list. |
Returns
Type | Description |
---|---|
int | The zero-based index of the first occurrence of item within the range of elements in the DynamicArray that extends from index to the last element, if found; otherwise, -1. |
IndexOf(T, int, int)
Searches for the specified object and returns the zero-based index of the first occurrence within the range of elements in the DynamicArray that starts at the specified index and contains the specified number of elements.
Declaration
public int IndexOf(T item, int index, int count)
Parameters
Type | Name | Description |
---|---|---|
T | item | The object to locate in the DynamicArray. The value can be null for reference types. |
int | index | The zero-based starting index of the search. 0 (zero) is valid in an empty list. |
int | count | The number of elements in the section to search. |
Returns
Type | Description |
---|---|
int |
Remove(T)
Removes the first occurrence of a specific object from the DynamicArray.
Declaration
public bool Remove(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The object to remove from the DynamicArray. The value can be null for reference types. |
Returns
Type | Description |
---|---|
bool | true if item is successfully removed; otherwise, false. This method also returns false if item was not found in the DynamicArray. |
RemoveAt(int)
Removes the element at the specified index of the DynamicArray.
Declaration
public void RemoveAt(int index)
Parameters
Type | Name | Description |
---|---|---|
int | index | The zero-based index of the element to remove. |
RemoveRange(int, int)
Removes a range of elements from the DynamicArray.
Declaration
public void RemoveRange(int index, int count)
Parameters
Type | Name | Description |
---|---|---|
int | index | The zero-based starting index of the range of elements to remove. |
int | count | The number of elements to remove. |
Reserve(int, bool)
Sets the total number of elements the internal data structure can hold without resizing.
Declaration
public void Reserve(int newCapacity, bool keepContent = false)
Parameters
Type | Name | Description |
---|---|---|
int | newCapacity | New capacity for the array. |
bool | keepContent | Set to true if you want the current content of the array to be kept. |
Resize(int, bool)
Resize the Dynamic Array. This will reallocate memory if necessary and set the current size of the array to the provided size.
Declaration
public void Resize(int newSize, bool keepContent = false)
Parameters
Type | Name | Description |
---|---|---|
int | newSize | New size for the array. |
bool | keepContent | Set to true if you want the current content of the array to be kept. |
SubRange(int, int)
Returns an IEnumeralbe-Like object that iterates through a subsection of this array.
Declaration
public DynamicArray<T>.RangeEnumerable SubRange(int first, int numItems)
Parameters
Type | Name | Description |
---|---|---|
int | first | The index of the first item |
int | numItems | The number of items to iterate |
Returns
Type | Description |
---|---|
DynamicArray<T>.RangeEnumerable |
|
Remarks
The returned struct intentionally does not explicitly implement the IEnumarable/IEnumerator interfaces it just follows
the same function signatures. This means the duck typing used by foreach
on the compiler level will
pick it up as IEnumerable but at the same time avoids generating Garbage.
For more info, see the C# language specification of the foreach
statement.
Operators
implicit operator T[](DynamicArray<T>)
Implicit conversion to regular array.
Declaration
public static implicit operator T[](DynamicArray<T> array)
Parameters
Type | Name | Description |
---|---|---|
DynamicArray<T> | array | Input DynamicArray. |
Returns
Type | Description |
---|---|
T[] | The internal array. |