CSharp · Console
using System;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
public static class Program
{
public static void Main()
{
double[,] testMulti =
{
{ 1, 2, 3, 4 },
{ 5, 6, 7, 8 },
{ 9, 9.5f, 10, 11 },
{ 12, 13, 14.3f, 15 }
};
var span = testMulti.AsSpan<double>();
var singleArray = new double[span.Length];
span.CopyTo(singleArray.AsSpan());
singleArray.Dump();
}
public static Span<T> AsSpan<T>(this Array array)
{
return MemoryMarshal.CreateSpan(ref Unsafe.As<byte, T>(ref MemoryMarshal.GetArrayDataReference(array)), array.Length);
}
}