I’ve seen a number of methods to copy a byte[] to a struct, and vise-versa. However, I was wondering if it was possible to cast the byte[] pointer to a struct (like you do in C)..
I want to be able to cast a byte[] to a struct, make changes to the struct, and have the changes automatically appear in the byte[].
Thanks,
reza
You just cast the pointer (sometimes you need to go via
void*in the middle):If you need to offset into the buffer, then use
byte* untyped = &buffer[offset].If you want a raw struct pointer, then:
However, note that you can’t pass a
Foo*to methods expecting aFooorref Foo.