docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class ReadOnlyHashSet<T>

    Wraps a HashSet<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
    ReadOnlyHashSet<T>
    Implements
    IReadOnlySet<T>
    IReadOnlyCollection<T>
    IEnumerable<T>
    IEnumerable
    IEquatable<ReadOnlyHashSet<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 ReadOnlyHashSet<T> : IReadOnlySet<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable, IEquatable<ReadOnlyHashSet<T>>
    Type Parameters
    Name Description
    T

    The element type.

    Remarks

    You are responsible to ensure that the underlying HashSet used by this class remains in scope for the lifetime of this class. If the HashSet is destroyed, methods in this class will throw exceptions.

    This collection is not thread-safe.

    Constructors

    ReadOnlyHashSet(HashSet<T>)

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

    Declaration
    public ReadOnlyHashSet(HashSet<T> set)
    Parameters
    Type Name Description
    HashSet<T> set

    The set to wrap.

    Exceptions
    Type Condition
    ArgumentNullException

    Thrown if set is null.

    Properties

    Count

    The number of elements in the read-only set.

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

    The number of elements.

    Methods

    Contains(T)

    Determines if the set contains a specific element.

    Declaration
    public bool Contains(T element)
    Parameters
    Type Name Description
    T element

    The element.

    Returns
    Type Description
    bool

    true if the set contains the element. Otherwise, false.

    CopyTo(List<T>)

    Copies the elements of the set to a list.

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

    The list.

    CopyTo(T[])

    Copies the elements of the set to an array.

    Declaration
    public void CopyTo(T[] array)
    Parameters
    Type Name Description
    T[] array

    The array.

    Empty()

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

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

    The empty read-only set.

    Remarks

    This method caches an empty read-only set 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 ReadOnlyHashSet instances compare equal if they are read-only views of the same HashSet instance.

    Equals(ReadOnlyHashSet<T>)

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

    Declaration
    public bool Equals(ReadOnlyHashSet<T> other)
    Parameters
    Type Name Description
    ReadOnlyHashSet<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 ReadOnlyHashSet instances compare equal if they are read-only views of the same HashSet instance.

    GetEnumerator()

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

    Declaration
    public HashSet<T>.Enumerator GetEnumerator()
    Returns
    Type Description
    HashSet<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()

    Implements

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