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
TThe 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
Span(T[])
Creates a new Span<T> over the entirety of a target array.
public Span(T[] array)
Parameters
arrayT[]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
arrayT[]The target array.
startintThe index at which to begin the span.
lengthintThe number of elements to include in the span.
Exceptions
- ArgumentOutOfRangeException
Thrown when
startorlengthis out of range.
Fields
Length
Gets the number of elements in the span.
public readonly int Length
Field Value
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
this[int]
Gets or sets the element at the specified index.
public ref T this[int index] { get; }
Parameters
indexintZero-based index of the element.
Property Value
- T
Exceptions
- IndexOutOfRangeException
Thrown when
indexis 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
destinationSpan<T>The target span.
Exceptions
- ArgumentException
Thrown when
destinationis 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
objobjectNot 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
valueTThe 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
startintThe index at which to begin the slice.
Returns
Exceptions
- ArgumentOutOfRangeException
Thrown when
startis 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
Returns
Exceptions
- ArgumentOutOfRangeException
Thrown when
startorlengthis out of range.
ToArray()
Copies the contents of this span into a new array.
public T[] ToArray()
Returns
- T[]
A new
Tarray containing the elements of this span.
ToString()
Returns the string representation of this Span<T>.
public override string ToString()
Returns
- string
If
Tis char, returns the span contents as a string; otherwise returns a descriptor in the formatSpan<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
destinationSpan<T>The target span.
Returns
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
Returns
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
segmentArraySegment<T>The source array segment.
Returns
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
spanSpan<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
arrayT[]The source array.
Returns
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)