docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class ListExtensions

    Extension methods for lists.

    Inheritance
    object
    ListExtensions
    Namespace: Unity.Collections
    Assembly: Unity.Collections.dll
    Syntax
    public static class ListExtensions

    Methods

    RemoveAtSwapBack<T>(List<T>, int)

    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.

    int 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>, 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
    bool

    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.

    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
    bool

    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.

    ToNativeArray<T>(List<T>, 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 : unmanaged
    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>, AllocatorHandle)

    Returns a copy of this list.

    Declaration
    public static NativeList<T> ToNativeList<T>(this List<T> list, AllocatorManager.AllocatorHandle allocator) where T : unmanaged
    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.

    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)