Struct ReadOnlyListSpan<T>
Wraps a list or array to provide a read-only view of some or all elements. Elements are not copied, so if the
underlying collection changes, the ReadOnlyListSpan
will see the updated elements.
Implements
Inherited Members
Namespace: Unity.XR.CoreUtils.Collections
Assembly: Unity.XR.CoreUtils.dll
Syntax
public struct ReadOnlyListSpan<T> : IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable, IEquatable<ReadOnlyListSpan<T>>
Type Parameters
Name | Description |
---|---|
T | The element type. |
Remarks
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.
This collection is not thread-safe.
Constructors
ReadOnlyListSpan(IReadOnlyList<T>)
Constructs a new instance of this class that is a read-only wrapper around the specified list.
Declaration
public ReadOnlyListSpan(IReadOnlyList<T> list)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyList<T> | list | The list to wrap. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
ReadOnlyListSpan(IReadOnlyList<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(IReadOnlyList<T> list, int start, int length)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyList<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 |
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. |
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 |
|
Overrides
Equals(ReadOnlyListSpan<T>)
Indicates whether the current object is equal to another object of the same type.
Declaration
public bool Equals(ReadOnlyListSpan<T> other)
Parameters
Type | Name | Description |
---|---|---|
ReadOnlyListSpan<T> | other | An object to compare with this object. |
Returns
Type | Description |
---|---|
bool |
|
Remarks
Two instances compare equal if they are read-only views of the same list, for the same start and end indices.
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. |
GetHashCode()
Get a hash code for this object.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
int | The hash code. |
Overrides
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. |
ToString()
Returns a string that represents the current object.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
string | The string. |
Overrides
Operators
operator ==(ReadOnlyListSpan<T>, ReadOnlyListSpan<T>)
Returns true
if objects are equal by Equals(ReadOnlyListSpan<T>).
Otherwise, false
.
Declaration
public static bool operator ==(ReadOnlyListSpan<T> lhs, ReadOnlyListSpan<T> rhs)
Parameters
Type | Name | Description |
---|---|---|
ReadOnlyListSpan<T> | lhs | The left-hand side of the comparison. |
ReadOnlyListSpan<T> | rhs | The right-hand side of the comparison. |
Returns
Type | Description |
---|---|
bool |
|
operator !=(ReadOnlyListSpan<T>, ReadOnlyListSpan<T>)
Returns false
if objects are equal by Equals(ReadOnlyListSpan<T>).
Otherwise, true
.
Declaration
public static bool operator !=(ReadOnlyListSpan<T> lhs, ReadOnlyListSpan<T> rhs)
Parameters
Type | Name | Description |
---|---|---|
ReadOnlyListSpan<T> | lhs | The left-hand side of the comparison. |
ReadOnlyListSpan<T> | rhs | The right-hand side of the comparison. |
Returns
Type | Description |
---|---|
bool |
|