比如有这样的c++代码:
struct A
{
...
...
union
{
...
...
}
}
用c#怎样实现
c++中的联合体在c#中怎样去实现?
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
1条回答 默认 最新
threenewbee 2016-10-10 03:22关注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; } } }本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报