Class ListExtensions
Extension methods for lists.
Namespace: Unity.Collections
Syntax
public static class ListExtensions
Methods
RemoveAtSwapBack<T>(List<T>, Int32)
Removes the value at an index.
Declaration
public static void RemoveAtSwapBack<T>(this List<T> list, int index)
Parameters
Type | Name | Description |
---|---|---|
List<T> | list | The list to search. |
Int32 | index | The index at which to remove an element from the list. |
Type Parameters
Name | Description |
---|---|
T | The type of elements in the list. |
Remarks
The value at the index is overwritten by the last element of the list, and the list's length is decremented by one.
RemoveSwapBack<T>(List<T>, T)
Finds and removes the first occurrence of a particular value in the list.
Declaration
public static bool RemoveSwapBack<T>(this List<T> list, T value)
Parameters
Type | Name | Description |
---|---|---|
List<T> | list | The list to search. |
T | value | The value to locate and remove. |
Returns
Type | Description |
---|---|
Boolean | Returns true if an element was removed. |
Type Parameters
Name | Description |
---|---|
T | The type of elements in the list. |
Remarks
If found, the first occurrence of the value is overwritten by the last element of the list, and the list's length is decremented by one.
RemoveSwapBack<T>(List<T>, Predicate<T>)
Finds and removes the first value which satisfies a predicate.
Declaration
public static bool RemoveSwapBack<T>(this List<T> list, Predicate<T> matcher)
Parameters
Type | Name | Description |
---|---|---|
List<T> | list | The list to search. |
Predicate<T> | matcher | The predicate for testing the elements of the list. |
Returns
Type | Description |
---|---|
Boolean | Returns true if an element was removed. |
Type Parameters
Name | Description |
---|---|
T | The type of elements in the list. |
Remarks
The first value satisfying the predicate is overwritten by the last element of the list, and the list's length is decremented by one.
ToNativeArray<T>(List<T>, AllocatorManager.AllocatorHandle)
Returns an array that is a copy of this list.
Declaration
public static NativeArray<T> ToNativeArray<T>(this List<T> list, AllocatorManager.AllocatorHandle allocator)
where T : struct
Parameters
Type | Name | Description |
---|---|---|
List<T> | list | The list to copy. |
AllocatorManager.AllocatorHandle | allocator | The allocator to use. |
Returns
Type | Description |
---|---|
NativeArray<T> | An array that is a copy of this list. |
Type Parameters
Name | Description |
---|---|
T | The type of elements in the list. |
ToNativeList<T>(List<T>, AllocatorManager.AllocatorHandle)
Returns a copy of this list.
Declaration
public static NativeList<T> ToNativeList<T>(this List<T> list, AllocatorManager.AllocatorHandle allocator)
where T : struct
Parameters
Type | Name | Description |
---|---|---|
List<T> | list | The list to copy. |
AllocatorManager.AllocatorHandle | allocator | The allocator to use. |
Returns
Type | Description |
---|---|
NativeList<T> | A copy of this list. |
Type Parameters
Name | Description |
---|---|
T | The type of elements in the list. |