Table of Contents

Struct Span<T>

Namespace
System
Assembly
C2JBridge.dll

Compatibility shim of Span<T> for .NET Framework targets.

This type is provided solely to allow JCOBridge public APIs that expose Span<T> (such as AsWritableSpan() and AsWritableSpan()) to compile and function correctly on .NET Framework without any external dependency. The implementation is backed by native pointer arithmetic and covers the subset of the API required by JCOBridge consumers.

JCOBridge HPA edition on .NET Framework uses the official System.Span<T> from the System.Memory NuGet package, which provides the full runtime-optimised implementation including SIMD support.

Users targeting .NET 5+ or .NET Standard 2.1 always receive the official runtime type — this shim is never compiled into those targets.

public readonly ref struct Span<T> where T : unmanaged

Type Parameters

T

The type of elements in the span. Must be an unmanaged type.

Inherited Members

Constructors

Span(void*, int)

Creates a new Span<T> from a raw pointer and a length.

public Span(void* ptr, int length)

Parameters

ptr void*

Pointer to the first element.

length int

Number of elements.

Span(T[])

Creates a new Span<T> over the entirety of a target array.

public Span(T[] array)

Parameters

array T[]

The target array.

Span(T[], int, int)

Creates a new Span<T> that includes a specified number of elements of an array starting at a specified index.

public Span(T[] array, int start, int length)

Parameters

array T[]

The target array.

start int

The index at which to begin the span.

length int

The number of elements to include in the span.

Exceptions

ArgumentOutOfRangeException

Thrown when start or length is out of range.

Fields

Length

Gets the number of elements in the span.

public readonly int Length

Field Value

int

Properties

Empty

Gets an empty Span<T>.

public static Span<T> Empty { get; }

Property Value

Span<T>

IsEmpty

Gets a value indicating whether this span is empty.

public bool IsEmpty { get; }

Property Value

bool

this[int]

Gets or sets the element at the specified index.

public ref T this[int index] { get; }

Parameters

index int

Zero-based index of the element.

Property Value

T

Exceptions

IndexOutOfRangeException

Thrown when index is negative or greater than or equal to Length.

Methods

Clear()

Clears the contents of this span by setting all elements to the default value of T.

public void Clear()

CopyTo(Span<T>)

Copies the contents of this span into a destination Span<T>.

public void CopyTo(Span<T> destination)

Parameters

destination Span<T>

The target span.

Exceptions

ArgumentException

Thrown when destination is shorter than this span.

Equals(object)

Not supported. Throws NotSupportedException.

[Obsolete("Equals() on Span is not supported. Use operator == instead.", true)]
public override bool Equals(object obj)

Parameters

obj object

Not used.

Returns

bool

Never returns — always throws NotSupportedException.

Fill(T)

Fills all elements of this span with the specified value.

public void Fill(T value)

Parameters

value T

The value to fill with.

GetEnumerator()

Returns an enumerator for this span, enabling foreach support.

public Span<T>.Enumerator GetEnumerator()

Returns

Span<T>.Enumerator

An Span<T>.Enumerator for this Span<T>.

GetHashCode()

Not supported. Throws NotSupportedException.

[Obsolete("GetHashCode() on Span is not supported.", true)]
public override int GetHashCode()

Returns

int

Never returns — always throws NotSupportedException.

GetPinnableReference()

Returns a reference to the first element for use with the fixed statement.

public ref T GetPinnableReference()

Returns

T

A reference to the first element, or a null reference if the span is empty.

Slice(int)

Forms a slice out of the current span starting at the specified index.

public Span<T> Slice(int start)

Parameters

start int

The index at which to begin the slice.

Returns

Span<T>

A Span<T> that consists of all elements from start to the end of the span.

Exceptions

ArgumentOutOfRangeException

Thrown when start is negative or greater than Length.

Slice(int, int)

Forms a slice out of the current span starting at the specified index for the specified length.

public Span<T> Slice(int start, int length)

Parameters

start int

The index at which to begin the slice.

length int

The desired length of the slice.

Returns

Span<T>

A Span<T> of length elements starting at start.

Exceptions

ArgumentOutOfRangeException

Thrown when start or length is out of range.

ToArray()

Copies the contents of this span into a new array.

public T[] ToArray()

Returns

T[]

A new T array containing the elements of this span.

ToString()

Returns the string representation of this Span<T>.

public override string ToString()

Returns

string

If T is char, returns the span contents as a string; otherwise returns a descriptor in the format Span<T>[Length].

TryCopyTo(Span<T>)

Attempts to copy the contents of this span into a destination Span<T> and returns a value indicating whether the operation succeeded.

public bool TryCopyTo(Span<T> destination)

Parameters

destination Span<T>

The target span.

Returns

bool

true if the copy succeeded; false if destination is too small.

Operators

operator ==(Span<T>, Span<T>)

Returns a value that indicates whether two Span<T> instances are equal.

public static bool operator ==(Span<T> left, Span<T> right)

Parameters

left Span<T>

The first span to compare.

right Span<T>

The second span to compare.

Returns

bool

true if the two spans point to the same memory and have the same length; otherwise false.

implicit operator Span<T>(ArraySegment<T>)

Implicitly converts an ArraySegment<T> to a Span<T>.

public static implicit operator Span<T>(ArraySegment<T> segment)

Parameters

segment ArraySegment<T>

The source array segment.

Returns

Span<T>

A Span<T> over the portion of the array described by segment.

implicit operator ReadOnlySpan<T>(Span<T>)

Implicitly converts a Span<T> to a ReadOnlySpan<T>.

public static implicit operator ReadOnlySpan<T>(Span<T> span)

Parameters

span Span<T>

The source span.

Returns

ReadOnlySpan<T>

A ReadOnlySpan<T> over the same memory as span.

implicit operator Span<T>(T[])

Implicitly converts a T array to a Span<T>.

public static implicit operator Span<T>(T[] array)

Parameters

array T[]

The source array.

Returns

Span<T>

A Span<T> over the entire array.

operator !=(Span<T>, Span<T>)

Returns a value that indicates whether two Span<T> instances are not equal.

public static bool operator !=(Span<T> left, Span<T> right)

Parameters

left Span<T>

The first span to compare.

right Span<T>

The second span to compare.

Returns

bool

true if the two spans are not equal; otherwise false.