ReadOnlyMemory<T> 结构

定义

表示相邻的内存区域,类似于 ReadOnlySpan<T>Represents a contiguous region of memory, similar to ReadOnlySpan<T>. ReadOnlySpan<T> 不同,它不是类似 byref 的类型。Unlike ReadOnlySpan<T>, it is not a byref-like type.

generic <typename T>
public value class ReadOnlyMemory : IEquatable<ReadOnlyMemory<T>>
public struct ReadOnlyMemory<T> : IEquatable<ReadOnlyMemory<T>>
type ReadOnlyMemory<'T> = struct
Public Structure ReadOnlyMemory(Of T)
Implements IEquatable(Of ReadOnlyMemory(Of T))

类型参数

T

要从中读取内存的连续区域的对象类型。The object type from which the contiguous region of memory will be read.

继承
ReadOnlyMemory<T>
实现

构造函数

ReadOnlyMemory<T>(T[])

在整个目标数组上创建新的内存区域。Creates a new memory region over the entirety of the target array.

ReadOnlyMemory<T>(T[], Int32, Int32)

在目标数组的一部分上创建新的内存区域,从指定位置开始并包含指定数量的元素。Creates a new memory region over the portion of the target array beginning at a specified position and including a specified number of elements.

属性

Empty

获取空的 ReadOnlyMemory<T>Gets an empty ReadOnlyMemory<T>.

IsEmpty

获取一个指示此只读内存区域是否为空的值。Gets a value that indicates whether this read-only memory region is empty.

Length

获取内存区域中的项数。Gets the number of items in the memory region.

Span

从内存区域获取跨度。Gets a span from the memory region.

方法

CopyTo(Memory<T>)

将只读内存区域的内容复制到目标内存区域。Copies the contents of the read-only memory region into a destination memory region.

Equals(Object)

确定指定的对象是否等于当前只读内存区域。Determines whether the specified object is equal to the current read-only memory region.

Equals(ReadOnlyMemory<T>)

确定当前实例与指定的 ReadOnlyMemory<T> 对象是否相等。Determines whether the current instance and a specified ReadOnlyMemory<T> objects are equal.

GetHashCode()

返回该 ReadOnlyMemory<T> 的哈希代码。Returns the hash code for this ReadOnlyMemory<T>.

Pin()

为内存创建句柄。Creates a handle for the memory.

Slice(Int32)

在给定内存区域外形成一个切片,从指定的位置开始,一直到它的结尾。Forms a slice out of the given memory region, beginning at a specified poisition and continuing to its end.

Slice(Int32, Int32)

length 元素的 start 位置开始,在给定内存区域外形成一个切片。Forms a slice out of the given memory region starting at start position for length elements.

ToArray()

将此内存区域中的内容复制到新数组中。Copies the contents from the memory region into a new array.

ToString()

返回此只读内存实例的字符串表示形式。Returns the string representation of this read-only memory instance.

TryCopyTo(Memory<T>)

尝试将只读内存的内容复制到目标中,并返回表示复制操作是否成功的值。Tries to copy the contents of the readonly-only memory into the destination and returns a value that indicates whether the copy operation succeeded.

操作员

Implicit(ArraySegment<T> to ReadOnlyMemory<T>)

定义 ArraySegment<T>ReadOnlyMemory<T> 的隐式转换。Defines an implicit conversion of a ArraySegment<T> to a ReadOnlyMemory<T>.

Implicit(T[] to ReadOnlyMemory<T>)

定义数组到 ReadOnlyMemory<T> 的隐式转换。Defines an implicit conversion of an array to a ReadOnlyMemory<T>.

扩展方法

Trim<T>(ReadOnlyMemory<T>, T)

删除只读内存区域中的指定元素的所有前导和尾随出现次数。Removes all leading and trailing occurrences of a specified element from a read-only memory region.

Trim<T>(ReadOnlyMemory<T>, ReadOnlySpan<T>)

从只读内存区域中删除在只读跨度中指定的一组元素的所有前导和尾随出现次数。Removes all leading and trailing occurrences of a set of elements specified in a read-only span from a read-only memory region.

TrimEnd<T>(ReadOnlyMemory<T>, T)

删除只读内存区域中的指定元素的所有尾随出现次数。Removes all trailing occurrences of a specified element from a read-only memory region.

TrimEnd<T>(ReadOnlyMemory<T>, ReadOnlySpan<T>)

从只读内存区域中删除在只读跨度中指定的一组元素的所有尾随出现次数。Removes all trailing occurrences of a set of elements specified in a read-only span from a read-only memory region.

TrimStart<T>(ReadOnlyMemory<T>, T)

删除内存区域中的指定元素的所有前导出现次数。Removes all leading occurrences of a specified element from a memory region.

TrimStart<T>(ReadOnlyMemory<T>, ReadOnlySpan<T>)

从内存区域中删除在只读跨度中指定的一组元素的所有前导出现次数。Removes all leading occurrences of a set of elements specified in a read-only span from a memory region.

适用于