I have been porting some C++ code to .net. I know C# doesn't have unions but
in order to write a particular algorythm efficiently i have a need to
address memory in in 2 different ways. As individual elements and also as an
array. I have tried the following (along with several variations) and none
work. Anyone have an alternative to what I am trying to do? The problem
comes when I want to have the int array occupy the same space as the 6 ints
defined above it. I would even try an 'unsafe' block using the 'fixed'
method but am having trouble getting that to work also. Seems there might be
some conflict with the other attributes I require possibly.
[StructLayout(LayoutKind.Explicit, Size = 24)]
public class TRIANGLE
{
[FieldOffset(0)] public int a;
[FieldOffset(4)] public int b;
[FieldOffset(8)] public int c;
[FieldOffset(12)] public int a_to_b;
[FieldOffset(16)] public int b_to_c;
[FieldOffset(20)] public int c_to_a;
[FieldOffset(0)] public int[] tri_pnt;
}
Any help would be greatly appreciated.
thanks
brian