Early Preview

This is currently very much a preview. Please feel free to try things out, but don't be upset if anything is not yet working. Feedback is welcome over on our GitHub Dicussions page.

struct System.​Span<​T>

Assembly: System.Runtime

Provides a type-safe and memory-safe representation of a contiguous region of arbitrary memory.

Properties

public static Span<​T>
Empty
Returns an empty <see cref="T:System.Span`1" /> object.
public bool
IsEmpty
Returns a value that indicates whether the current <see cref="T:System.Span`1" /> is empty.
public T&
Item
public int
Length
Returns the length of the current span.

Methods

public void
Clear​()
Clears the contents of this <see cref="T:System.Span`1" /> object.
public void
CopyTo​(Span<​T> destination)
Copies the contents of this <see cref="T:System.Span`1" /> into a destination <see cref="T:System.Span`1" /> .
destination The destination <see cref="T:System.Span`1" /> object.
public bool
Equals​(object obj)
Calls to this method are not supported.
Returns Calls to this method are not supported.
obj Not supported.
public void
Fill​(T value)
Fills the elements of this span with a specified value.
value The value to assign to each element of the span.
public Enumerator<​T>
GetEnumerator​()
Returns an enumerator for this <see cref="T:System.Span`1" /> .
Returns An enumerator for this span.
public int
GetHashCode​()
Throws a <see cref="T:System.NotSupportedException" /> .
Returns Calls to this method always throw a <see cref="T:System.NotSupportedException" /> .
public T&
GetPinnableReference​()
Returns a reference to an object of type T that can be used for pinning. This method is intended to support .NET compilers and is not intended to be called by user code.
Returns A reference to the element of the span at index 0, or <see langword="null" /> if the span is empty.
public Span<​T>
Slice​(int start)
Forms a slice out of the current span that begins at a specified index.
Returns A span that consists of all elements of the current span from <paramref name="start" /> to the end of the span.
start The zero-based index at which to begin the slice.
public Span<​T>
Slice​(int start, int length)
Forms a slice out of the current span starting at a specified index for a specified length.
Returns A span that consists of <paramref name="length" /> elements from the current span starting at <paramref name="start" /> .
start The zero-based index at which to begin this slice.
length The desired length for the slice.
public T[]
ToArray​()
Copies the contents of this span into a new array.
Returns An array containing the data in the current span.
public string
ToString​()
Returns the string representation of this <see cref="T:System.Span`1" /> object.
Returns The string representation of this <see cref="T:System.Span`1" /> object.
public bool
TryCopyTo​(Span<​T> destination)
Attempts to copy the current <see cref="T:System.Span`1" /> to a destination <see cref="T:System.Span`1" /> and returns a value that indicates whether the copy operation succeeded.
Returns <see langword="true" /> if the copy operation succeeded; otherwise, <see langword="false" /> .
destination The target of the copy operation.
protected void
Finalize​()
Inherited from object
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
public Type
GetType​()
Inherited from object
Gets the <see cref="T:System.Type" /> of the current instance.
Returns The exact runtime type of the current instance.
protected object
MemberwiseClone​()
Inherited from object
Creates a shallow copy of the current <see cref="T:System.Object" /> .
Returns A shallow copy of the current <see cref="T:System.Object" /> .