5
Reply

struct with static array inside

fearedpixel

fearedpixel

Dec 16 2003 7:03 AM
1.8k
I am writing a 3d vector class, it has 3 floats in it, x, y and z. I need to provide array access to these values. In C++ I could use union to make a static array reference the same part of memory as the 3 floats. I would like to do something similar in C#, so I dont have to build an array of identical information from the floats every time i need them as an array. The StructLayout attribute with FieldOffset seems like the perfect way to do this, but its no use with arrays since there is only dynamic arrays and not static ones. Can anyone suggest a way I could achieve this? Or is it possible to somehow cast an instance of a struct into an array?

Answers (5)
Next Recommended Forum