Table of Contents

Class PrimitiveArray<T>

Namespace
CStructSharp.Values
Assembly
CStructSharp.dll

A parsed one-dimensional array of a fixed-width numeric primitive, stored as a T[]. It is the IList<T> of object the documented value table promises for arrays - enumeration, indexing and passing it back to Serialize/Update all work - while Span and ToArray() expose the values without boxing. Like a .NET array it is fixed size: elements can be replaced through the indexer, never added or removed.

public sealed class PrimitiveArray<T> : IList<object?>, ICollection<object?>, IReadOnlyList<object?>, IReadOnlyCollection<object?>, IEnumerable<object?>, IList, ICollection, IEnumerable where T : unmanaged

Type Parameters

T

The element type: byte, sbyte, bool, the 16/32/64-bit integers, float or double.

Inheritance
PrimitiveArray<T>
Implements
Inherited Members

Constructors

PrimitiveArray(T[])

Wraps values without copying.

public PrimitiveArray(T[] values)

Parameters

values T[]

The element storage; the array shares it.

Properties

Count

Gets the number of elements.

public int Count { get; }

Property Value

int

this[int]

Gets or replaces one element; the boxed element is a T, and a replacement is converted to T.

public object? this[int index] { get; set; }

Parameters

index int

The zero-based element index.

Property Value

object

Memory

Gets the elements as typed read-only memory (no boxing).

public ReadOnlyMemory<T> Memory { get; }

Property Value

ReadOnlyMemory<T>

Span

Gets the elements as a typed read-only span (no boxing).

public ReadOnlySpan<T> Span { get; }

Property Value

ReadOnlySpan<T>

Methods

Contains(object?)

Returns whether any element equals item.

public bool Contains(object? item)

Parameters

item object

The value to find.

Returns

bool

true when found.

CopyTo(object?[], int)

Copies the boxed elements into array.

public void CopyTo(object?[] array, int arrayIndex)

Parameters

array object[]

The destination.

arrayIndex int

The destination start index.

GetEnumerator()

Enumerates the elements as boxed values.

public IEnumerator<object?> GetEnumerator()

Returns

IEnumerator<object>

An enumerator over the boxed elements.

IndexOf(object?)

Finds the first element equal to item.

public int IndexOf(object? item)

Parameters

item object

The value to find; compared after conversion to T when possible.

Returns

int

The index, or -1.

ToArray()

Copies the elements into a new typed array.

public T[] ToArray()

Returns

T[]

A fresh T[] with the same values.

ToString()

Describes the array for debugging.

public override string ToString()

Returns

string

The element type and count.