15
22

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

SpanとかMemoryとかIntPtrとかArrayの変換方法チートシート

Last updated at Posted at 2019-07-21

自分用のチートシートです。
MSDNマガジンをベースに

変換元 変換先 メソッド Copied
ArraySegment<T> Memory<T> 暗黙のキャスト、
AsMemory()
ArraySegment<T> ReadOnlyMemory<T> 暗黙のキャスト、
AsReadOnlyMemory()
ArraySegment<T> ReadOnlySpan<T> 暗黙のキャスト、
AsReadOnlySpan()
ArraySegment<T> Span<T> 暗黙のキャスト、
AsSpan()
ArraySegment<T> T[] Arrayプロパティ
IntPtr String Marshal.PtrToString{Uni,Auto,Ansi}() *
IntPtr T Marshal.PtrToStructure() *
IntPtr T* キャスト
IntPtr void* ToPointer()
IntPtr Span<T> なし(無理やり変換する方法)
Memory<T> ArraySegment<T> SRIS.MemoryMarshal.TryGetArray()
Memory<T> ReadOnlyMemory<T> 暗黙のキャスト
Memory<T> Span<T> Spanプロパティ
Memory<T> T[] ToArray() *
ReadOnlyMemory<char> string ToString() *
ReadOnlyMemory<char> 素のstring SRIS.MemoryMarshal.TryGetString()
ReadOnlyMemory<T> ArraySegment<T> SRIS.MemoryMarshal.TryGetArray()
ReadOnlyMemory<T> IEnumerable<T> SRIS.MemoryMarshal.ToEnumerable()
ReadOnlyMemory<T> Memory<T> SRIS.MemoryMarshal.AsMemory()
ReadOnlyMemory<T> ReadOnlySpan<T> Spanプロパティ
ReadOnlyMemory<T> T[] ToArray() *
ReadOnlyMemory<T> TManager : System.Buffers.MemoryManager<T> SRIS.MemoryMarshal.TryGetMemoryManager()
ReadOnlySpan<T> string ToString() *
ReadOnlySpan<T> T* fixedステートメント
ReadOnlySpan<T> ref readonly T インデクサー取得アクセサー、
SRIS.MemoryMarshal.GetReference()
ReadOnlySpan<T> where T : struct ReadOnlySpan<byte> SRIS.MemoryMarshal.AsBytes()
ReadOnlySpan<TFrom> where T : struct ReadOnlySpan<TTo> where T : struct SRIS.MemoryMarshal.Cast()
ref byte T SRCS.Unsafe.Read() *
ref T ReadOnlySpan<T> SRIS.MemoryMarshal.CreateReadOnlySpan()
ref T Span<T> SRIS.MemoryMarshal.CreateSpanメソッド`
ref T void* SRCS.Unsafe.AsPointer()
ref TFrom ref TTo SRCS.Unsafe.As()
ref T where T : struct Span<byte> SRIS.MemoryMarshal.TryWriteメソッド、
SRIS.MemoryMarshal.Write()
Span<byte> ref T where T : struct SRIS.MemoryMarshal.AsRef()
Span<byte> T where T : struct SRIS.MemoryMarshal.TryReadメソッド、
SRIS.MemoryMarshal.Read()
*
Span<char> string ToString() *
Span<T> T* fixedステートメント
Span<T> ReadOnlySpan<T> 暗黙のキャスト
Span<T> ref T ref span[0]
GetPinnableReference()
SRIS.MemoryMarshal.GetReference()
Span<T> where T : struct Span<byte> SRIS.MemoryMarshal.AsBytes()
Span<TFrom> where T : struct Span<TTo> where T : struct SRIS.MemoryMarshal.Cast()
String char* fixedステートメント
String ReadOnlyMemory<char> AsReadOnlyMemory()
String ReadOnlySpan<char> 暗黙のキャスト、AsSpan()
String(Pinned) IntPtr GCHandle.AddrOfPinnedObject()
T[] ArraySegment<T> ctor、暗黙のキャスト
T[] Memory<T> ctor、暗黙のキャスト、
AsMemory()
*
T[] ReadOnlyMemory<T> ctor、暗黙のキャスト、
AsReadOnlyMemory()
T[] ReadOnlySpan<T> ctor、暗黙のキャスト、
AsReadOnlySpan()
T[] Span<T> ctor、暗黙のキャスト、
AsSpan()
T[](Pinned) IntPtr Marshal.UnsafeAddrOfPinnedArrayElement()
GCHandle.AddrOfPinnedObject()
*
T[](Pinned) Memory<T> SRIS.MemoryMarshal.CreateFromPinnedArray()
void* IntPtr ctor
void* ReadOnlySpan<T> ctor *
void* ref T SRCS.Unsafe.AsRefメソッド
void* Span<T> ctor

SRIS: System.Runtime.InteropServices
SRCS: System.Runtime.CompilerServices

15
22
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
22

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?