Marshal.Copy:
public static void Copy(
byte[] source,
int startIndex,
IntPtr destination,
int length
);
Parameters
source
The one-dimensional array to copy from.
startIndex
The zero-based index into the array where Copy should start.
destination
The memory pointer to copy to.
length
The number of array elements to copy.
例子:
byte[] ba ={ 'a', 'b', 'c', 'd' };
IntPtr p = Marshal.AllocCoTaskMem(ba.Length);
Marshal.Copy(ba, 0, p, ba.Length);