Regarding passing arrays to functions and then manipulating the array contents (Array.Reverse) and then using pointers I extract the values from the array. But before jumping into the function, here is what I do;
byte[] arrayA = OriginalArray
byte[] arrayB = arrayA;
manipulate(OriginalArray);
And the function abstracted, looks like this
manipulateArray(byte[] OriginalArray) // This is unsafe
{
// Unsafe code that keeps a pointer to OriginalArray
// Array reverse
// Value extraction via pointer
}
After doing so, to my surprise what I am getting is that arrayB now “has” its values manipulated as if I had passed it to the function! Unless I missed something, I am pretty sure that I have not done something wrong. I made sure that the function is called after the arrayA and arrayB assignments.
Need guidance on this.
Thanks
If you want arrayB to retain the same values you’ll need to make a copy of arrayA. Both arrayA and arrayB are pointing to the same reference in your example.
Here’s a quick example to illustrate the point: