I have an object
parameter that is being called via COM interop and the type of the object coming in is System.Byte[*]
and I want to get it to a byte[]
; is there a way to do this without copying?
Both an explicit cast and the as
keyword both fail. The odd thing is that both of those methods work how I want in the 'Immediate' window if I break in my function.
public void DoIt(object param) {
var bbuf = param as byte[];
// bbuf is NULL here
bbuf = (byte[])param;
// Throws cast exception
// This works, but I don't want to copy
var abuf = param as Array;
bbuf = new byte[abuf.Length];
abuf.CopyTo(bbuf, 0);
}