UNION with nested Structs

  • Thread starter Thread starter Sean S.
  • Start date Start date
S

Sean S.

I have been following the strings of Unions here however I have not yet
seen any that can help me with this one... I am needing to convert some
16bit C code into C#... can some one assist? Here is a bit of the code:

typedef union
{
struct
{
int nZWord;
int nFId;
};

struct
{
int nFieldId;
int nIndex;
};

} MARKER;


Any assistance is appreciated... Thanks!

SFS
 
Sean,

You could do this in the following manner:

[StructLayout(LayoutKind.Explicit)]
public struct MARKER
{
[FieldOffset(0)]
public int nZWord;
[FieldOffset(4)]
public int nFId;
[FieldOffset(0)]
public int nFieldId;
[FieldOffset(4)]
public int nIndex;
}

For more information on how to marshal structures with unions (or unions
in general), check out the section of the .NET framework documentation
titled "Unions Sample".

Hope this helps.
 
Back
Top