docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class ReadOnlyList<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.

    Inheritance
    object
    ReadOnlyList<T>
    Implements
    IReadOnlyList<T>
    IReadOnlyCollection<T>
    IEnumerable<T>
    IEnumerable
    IEquatable<ReadOnlyList<T>>
    Inherited Members
    object.Equals(object, object)
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    Namespace: Unity.XR.CoreUtils.Collections
    Assembly: Unity.XR.CoreUtils.dll
    Syntax
    public class ReadOnlyList<T> : IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable, IEquatable<ReadOnlyList<T>>
    Type Parameters
    Name Description
    T

    The element type.

    Remarks

    This collection is not thread-safe.

    Constructors

    ReadOnlyList(List<T>)

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

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

    The list to wrap.

    Exceptions
    Type Condition
    ArgumentNullException

    Thrown if list is null.

    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 ReadOnlyList<T> Empty()
    Returns
    Type Description
    ReadOnlyList<T>

    The empty read-only list.

    Remarks

    This method caches an empty read-only list that you can re-use throughout the life cycle of your app.

    Equals(object)

    Indicates whether the current object is equal to another object of the same type.

    Declaration
    public override bool Equals(object obj)
    Parameters
    Type Name Description
    object obj

    An object to compare with this object.

    Returns
    Type Description
    bool

    true if the current object is equal to the other parameter. Otherwise, false.

    Overrides
    object.Equals(object)
    Remarks

    Two ReadOnlyList instances compare equal if they are read-only views of the same list instance.

    Equals(ReadOnlyList<T>)

    Indicates whether the current object is equal to another object of the same type.

    Declaration
    public bool Equals(ReadOnlyList<T> other)
    Parameters
    Type Name Description
    ReadOnlyList<T> other

    An object to compare with this object.

    Returns
    Type Description
    bool

    true if the current object is equal to the other parameter. Otherwise, false.

    Remarks

    Two ReadOnlyList instances compare equal if they are read-only views of the same list instance.

    GetEnumerator()

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

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

    The enumerator.

    GetHashCode()

    Get a hash code for this object.

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    int

    The hash code.

    Overrides
    object.GetHashCode()

    ToString()

    Returns a string that represents the current object.

    Declaration
    public override string ToString()
    Returns
    Type Description
    string

    The string.

    Overrides
    object.ToString()

    Operators

    operator ==(ReadOnlyList<T>, ReadOnlyList<T>)

    Returns true if objects are equal by Equals(ReadOnlyList<T>). Otherwise, false.

    Declaration
    public static bool operator ==(ReadOnlyList<T> lhs, ReadOnlyList<T> rhs)
    Parameters
    Type Name Description
    ReadOnlyList<T> lhs

    The left-hand side of the comparison.

    ReadOnlyList<T> rhs

    The right-hand side of the comparison.

    Returns
    Type Description
    bool

    true if objects are equal. Otherwise, false.

    operator !=(ReadOnlyList<T>, ReadOnlyList<T>)

    Returns false if objects are equal by Equals(ReadOnlyList<T>). Otherwise, true.

    Declaration
    public static bool operator !=(ReadOnlyList<T> lhs, ReadOnlyList<T> rhs)
    Parameters
    Type Name Description
    ReadOnlyList<T> lhs

    The left-hand side of the comparison.

    ReadOnlyList<T> rhs

    The right-hand side of the comparison.

    Returns
    Type Description
    bool

    false if objects are equal. Otherwise, true.

    Implements

    IReadOnlyList<T>
    IReadOnlyCollection<T>
    IEnumerable<T>
    IEnumerable
    IEquatable<T>
    In This Article
    Back to top
    Copyright © 2025 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)