Is there a simple way to downcast an array of integers into an array of bytes?
Essentially, I would like to do the following thing (which does not work as is):
int[] myIntArray = new int[20];
byte[] byteArray = (byte[])myInArray;
The reason for doing this is that in my application myIntArray is actually a byte[], but was declared as an int[]. Meaning that only the least significant byte in myIntArray is of interest.
myIntArray is actually a byte[], but was declared as an int[]- How did you get that to happen? P/Invoke? If so, correct the P/Invoke signature.intarray contains values like 0x00000001, 0x00000002, 0x00000003 then it is NOT an array of bytes at all; it really is an array of ints.DllImportdeclaration. What does that look like? However, I'm thinking that what you have really is an array ofintvalues (occupying 4 bytes each, but with only the lsb being non-zero), so you really can't cast it or fix it by changing the DLLImport declaration.