docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Struct ReadOnlyListSpan<T>

    Wraps a List<T> to provide a read-only view of its memory without copying any elements. It is preferable to use this collection in API designs instead of IReadOnlyCollection because GetEnumerator() returns a value-type enumerator and does not perform any heap allocations. Additionally, this collection has the ability to provide a slice of a list.

    Implements
    IReadOnlyList<T>
    IReadOnlyCollection<T>
    IEnumerable<T>
    IEnumerable
    Inherited Members
    ValueType.Equals(object)
    ValueType.GetHashCode()
    ValueType.ToString()
    object.Equals(object, object)
    object.GetType()
    object.ReferenceEquals(object, object)
    Namespace: Unity.XR.CoreUtils.Collections
    Assembly: Unity.XR.CoreUtils.dll
    Syntax
    public struct ReadOnlyListSpan<T> : IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable
    Type Parameters
    Name Description
    T

    The element type.

    Remarks

    This collection is not thread-safe.

    Constructors

    ReadOnlyListSpan(List<T>)

    Constructs a new instance of this class that is a read-only wrapper around the specified list.

    Declaration
    public ReadOnlyListSpan(List<T> list)
    Parameters
    Type Name Description
    List<T> list

    The list to wrap.

    Exceptions
    Type Condition
    ArgumentNullException

    Thrown if list is null.

    ReadOnlyListSpan(List<T>, int, int)

    Constructs a new instance of this class that is a read-only wrapper around a slice of the specified list.

    Declaration
    public ReadOnlyListSpan(List<T> list, int start, int length)
    Parameters
    Type Name Description
    List<T> list

    The list to wrap.

    int start

    The zero-based index at which to begin this slice.

    int length

    The desired length for the slice.

    Exceptions
    Type Condition
    ArgumentNullException

    Thrown if list is null.

    ArgumentOutOfRangeException

    Thrown if start or length are outside the bounds of the list.

    Properties

    Count

    The number of elements in the read-only list.

    Declaration
    public int Count { get; }
    Property Value
    Type Description
    int

    The number of elements.

    this[int]

    Returns the element at index.

    Declaration
    public T this[int index] { get; }
    Parameters
    Type Name Description
    int index

    The index.

    Property Value
    Type Description
    T

    Methods

    Empty()

    Returns an empty read-only list with the specified type argument.

    Declaration
    public static ReadOnlyListSpan<T> Empty()
    Returns
    Type Description
    ReadOnlyListSpan<T>

    The empty read-only list.

    GetEnumerator()

    Returns an enumerator that iterates through the read-only list.

    Declaration
    public ReadOnlyListSpan<T>.Enumerator GetEnumerator()
    Returns
    Type Description
    ReadOnlyListSpan<T>.Enumerator

    The enumerator.

    Slice(int, int)

    Modifies the existing list to form a slice starting at a specified index for a specified length.

    Declaration
    public ReadOnlyListSpan<T> Slice(int start, int length)
    Parameters
    Type Name Description
    int start

    The zero-based index at which to begin this slice.

    int length

    The desired length for the slice.

    Returns
    Type Description
    ReadOnlyListSpan<T>

    A new ReadOnlyListSpan<T> that is a read only view of a slice of a list.

    Exceptions
    Type Condition
    ArgumentOutOfRangeException

    Thrown if start or length are outside the bounds of the current ReadOnlyListSpan.

    Implements

    IReadOnlyList<T>
    IReadOnlyCollection<T>
    IEnumerable<T>
    IEnumerable
    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)