Struct ReadOnlyStructSpan<T>
Wraps a list, array, or NativeArray to provide a read-only view of some or all elements. Elements are not
copied, so if the underlying collection changes, the ReadOnlyStructSpan will see the updated elements.
Implements
Inherited Members
Namespace: Unity.XR.CoreUtils.Collections
Assembly: Unity.XR.CoreUtils.dll
Syntax
public struct ReadOnlyStructSpan<T> : IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable, IEquatable<ReadOnlyStructSpan<T>> where T : struct
Type Parameters
| Name | Description |
|---|---|
| T | The element type. Must be a struct. |
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
ReadOnlyStructSpan(IReadOnlyList<T>)
Constructs a new instance of this struct that is a read-only wrapper around the specified list.
Declaration
public ReadOnlyStructSpan(IReadOnlyList<T> list)
Parameters
| Type | Name | Description |
|---|---|---|
| IReadOnlyList<T> | list | The list to wrap. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if |
ReadOnlyStructSpan(IReadOnlyList<T>, int, int)
Constructs a new instance of this struct that is a read-only wrapper around a slice of the specified list.
Declaration
public ReadOnlyStructSpan(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. |
ReadOnlyStructSpan(NativeArray<T>)
Constructs a new instance of this struct that is a read-only wrapper around the specified NativeArray.
Declaration
public ReadOnlyStructSpan(NativeArray<T> nativeArray)
Parameters
| Type | Name | Description |
|---|---|---|
| NativeArray<T> | nativeArray | The NativeArray to wrap. |
ReadOnlyStructSpan(NativeArray<T>, int, int)
Constructs a new instance of this struct that is a read-only wrapper around a slice of the specified
NativeArray.
Declaration
public ReadOnlyStructSpan(NativeArray<T> nativeArray, int start, int length)
Parameters
| Type | Name | Description |
|---|---|---|
| NativeArray<T> | nativeArray | The |
| int | start | The zero-based index at which to begin this slice. |
| int | length | The desired length for the slice. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown if |
Properties
Count
The number of elements in the read-only span.
Declaration
public readonly int Count { get; }
Property Value
| Type | Description |
|---|---|
| int | The number of elements. |
End
The exclusive end index of a slice of the collection.
Declaration
public readonly int End { get; }
Property Value
| Type | Description |
|---|---|
| int |
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 |
Start
The inclusive start index of a slice of the collection.
Declaration
public readonly int Start { get; }
Property Value
| Type | Description |
|---|---|
| int |
Methods
Empty()
Returns an empty instance with the specified type argument.
Declaration
public static ReadOnlyStructSpan<T> Empty()
Returns
| Type | Description |
|---|---|
| ReadOnlyStructSpan<T> | The empty read-only span. |
Equals(object)
Indicates whether the current object is equal to another object, which must be 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(ReadOnlyStructSpan<T>)
Indicates whether the current object is equal to another object of the same type.
Declaration
public bool Equals(ReadOnlyStructSpan<T> other)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlyStructSpan<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 collection with the same start and end indices.
GetEnumerator()
Returns an enumerator that iterates through the read-only span.
Declaration
public ReadOnlyStructSpan<T>.Enumerator GetEnumerator()
Returns
| Type | Description |
|---|---|
| ReadOnlyStructSpan<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)
Create a new instance using a subset of the current span.
Indices are mapped within the current instance's span, so index 0 refers to the start index of this
span, etc.
Declaration
public ReadOnlyStructSpan<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 |
|---|---|
| ReadOnlyStructSpan<T> | A slice of the current instance. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown if |
ToString()
Returns a string that represents the current object.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string | The string. |
Overrides
Operators
operator ==(ReadOnlyStructSpan<T>, ReadOnlyStructSpan<T>)
Returns true if objects are equal by Equals(ReadOnlyStructSpan<T>).
Otherwise, false.
Declaration
public static bool operator ==(ReadOnlyStructSpan<T> lhs, ReadOnlyStructSpan<T> rhs)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlyStructSpan<T> | lhs | The left-hand side of the comparison. |
| ReadOnlyStructSpan<T> | rhs | The right-hand side of the comparison. |
Returns
| Type | Description |
|---|---|
| bool |
|
operator !=(ReadOnlyStructSpan<T>, ReadOnlyStructSpan<T>)
Returns false if objects are equal by Equals(ReadOnlyStructSpan<T>).
Otherwise, true.
Declaration
public static bool operator !=(ReadOnlyStructSpan<T> lhs, ReadOnlyStructSpan<T> rhs)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlyStructSpan<T> | lhs | The left-hand side of the comparison. |
| ReadOnlyStructSpan<T> | rhs | The right-hand side of the comparison. |
Returns
| Type | Description |
|---|---|
| bool |
|