C#实现联合体

时间:2022-09-05 18:43:05
        [StructLayout(LayoutKind.Explicit, Size = 8)]
        public struct TypeTransform
        {
            [FieldOffset(0)]
            public float f;

            [FieldOffset(0)]
            public int i;

            [FieldOffset(0)]
            public double d;

            [FieldOffset(0)]
            public long l;

            //[FieldOffset(0)]
            //public byte b1;

            //[FieldOffset(1)]
            //public byte b2;

            //[FieldOffset(2)]
            //public byte b3;

            //[FieldOffset(3)]
            //public byte b4;
        }