比如有这样的c++代码:
struct A
{
...
...
union
{
...
...
}
}
用c#怎样实现
C#没有联合体,不过可以用属性实现相似的功能
C++的union
union MyUnion
{
int x;
struct
{
short hi;
short low;
} value;
}
用C#可以写
struct MyUnion
{
public int x;
public short hi { get { return x / 65536; } set { x = value * 65536 + x % 65536; } }
public short low { get { return x % 65536 } set { x = x - x % 65536 + value; } }
}