There is no Marshal.Copy
overload that takes an unsigned short array. Fortunately, ushort
and short
are the same size, so you can use the Marshal.Copy(Int16[], IntPtr, int)
overload. You just need to coerce your ushort[]
into a short[]
first.
Probably the fastest way to do this is to use Buffer.BlockCopy
. It copies bytes, so you just have to tell it to copy 2 bytes per entry:
short[] temp = new short[bufferArray.Length];
System.Buffer.BlockCopy(bufferArray, 0, temp, 0, temp.Length * 2);
This will copy the unsigned 16-bit integer values into a signed 16-bit integer array, but the underlying byte values will remain the same, and the unmanaged code won't know the difference.