Proper way to get a mutable struct for Memory<byte> / Span<byte>?
问题 For a network protocol implementation I want to make use of the new Memory and Span classes to achieve zero-copy of the buffer while accessing the data through a struct . I have the following contrived example: [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct Data { public int IntValue; public short ShortValue; public byte ByteValue; } static void Prepare() { var buffer = new byte[1024]; var dSpan = MemoryMarshal.Cast<byte, Data>(buffer); ref var d = ref dSpan[0]; d.ByteValue = 1