文章转自:http://social.msdn.microsoft.com/Forums/zh-CN/visualcshartzhchs/thread/8b050320-37b7-4bbf-90b6-b966eb48af24 c++原结构体如下 : typedef struct { /* CAN_MSG */ union { UINT8 id[4]; UINT32 identifier; }; union { struct { UINT8 length :4; /* data length */ UINT8 resbit :2; UINT8 remote :1; /* remote transmission request */ UINT8 format :1; /* frame format */ }; UINT8 info; }; UINT8 reserve[3]; UINT8 data[8]; /* data field */ } CAN_MSG; C#对应如下: using System.Runtime.InteropServices; public class CAN_MSG // CAN_MSG { //Unions are not supported in C#, but the following union can be simulated with the StructLayout and FieldOffset attributes. //ORIGINAL LINE: union //Structs must be named in C#, so the following struct has been named AnonymousStruct: [StructLayout(LayoutKind.Explicit)] public struct AnonymousStruct { [FieldOffset(0)] public byte[] id = new byte[4]; [FieldOffset(0)] public uint identifier; } //Unions are not supported in C#. //ORIGINAL LINE: union //Structs must be named in C#, so the following struct has been named AnonymousStruct2: public struct AnonymousStruct2 { //Classes must be named in C#, so the following class has been named AnonymousClass: public class AnonymousClass { //C# does not allow bit fields: public byte length :4; // data length public byte resbit :2; public byte remote :1; // remote transmission request public byte format :1; // frame format } public byte info; } public byte[] reserve = new byte[3]; public byte[] data = new byte[8]; // data field }