Table of Contents

Struct ReadOnlyArray<T>

Namespace
LfrlAnvil
Assembly
LfrlAnvil.Core.dll

A lightweight generic read-only container for an Array.

public readonly struct ReadOnlyArray<T> : IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable

Type Parameters

T
Implements
Inherited Members
Extension Methods

Constructors

ReadOnlyArray(T[])

Creates a new ReadOnlyArray<T> instance.

public ReadOnlyArray(T[] source)

Parameters

source T[]

Underlying Array.

Fields

Empty

Represents a empty read-only Array.

public static readonly ReadOnlyArray<T> Empty

Field Value

ReadOnlyArray<T>

Properties

Count

Gets the number of elements in the collection.

public int Count { get; }

Property Value

int

The number of elements in the collection.

this[int]

Gets the element at the specified index in the read-only list.

public T this[int index] { get; }

Parameters

index int

The zero-based index of the element to get.

Property Value

T

The element at the specified index in the read-only list.

Methods

AsMemory()

Creates a new ReadOnlyMemory<T> instance from this ReadOnlyArray<T>.

[Pure]
public ReadOnlyMemory<T> AsMemory()

Returns

ReadOnlyMemory<T>

New ReadOnlyMemory<T> instance.

AsSpan()

Creates a new ReadOnlySpan<T> instance from this ReadOnlyArray<T>.

[Pure]
public ReadOnlySpan<T> AsSpan()

Returns

ReadOnlySpan<T>

New ReadOnlySpan<T> instance.

From<TSource>(ReadOnlyArray<TSource>)

Creates a new ReadOnlyArray<T> instance.

[Pure]
public static ReadOnlyArray<T> From<TSource>(ReadOnlyArray<TSource> source) where TSource : class?, T

Parameters

source ReadOnlyArray<TSource>

Other read-only array.

Returns

ReadOnlyArray<T>

New ReadOnlyArray<T> instance.

Type Parameters

TSource

Array element type convertible to read-only array's element type.

From<TSource>(TSource[])

Creates a new ReadOnlyArray<T> instance.

[Pure]
public static ReadOnlyArray<T> From<TSource>(TSource[] source) where TSource : class?, T

Parameters

source TSource[]

Underlying array.

Returns

ReadOnlyArray<T>

New ReadOnlyArray<T> instance.

Type Parameters

TSource

Array element type convertible to read-only array's element type.

GetEnumerator()

Creates a new ReadOnlyArray<T>.Enumerator instance for this sequence.

[Pure]
public ReadOnlyArray<T>.Enumerator GetEnumerator()

Returns

ReadOnlyArray<T>.Enumerator

New ReadOnlyArray<T>.Enumerator instance.

GetUnderlyingArray()

Returns the underlying array.

[Pure]
public IReadOnlyList<T> GetUnderlyingArray()

Returns

IReadOnlyList<T>

The underlying array.

Operators

implicit operator ReadOnlyArray<T>(T[])

Converts the provided source to ReadOnlyArray<T>.

[Pure]
public static implicit operator ReadOnlyArray<T>(T[] source)

Parameters

source T[]

Underlying array.

Returns

ReadOnlyArray<T>

New ReadOnlyArray<T> instance.