C#结构体大小问题

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace Struct
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("结构体大小:"+Marshal.SizeOf(new DataSize()));
            Console.ReadKey();
        }

    }
    //可序列化 设置对齐值为1
     [Serializable, StructLayout(LayoutKind.Sequential, Pack = 1)]  
    public struct DataSize
    {
        public ushort a;//对齐值2
        public char b;//1
        public ushort c;//2
        public uint d;//4
        public char e;//1
        public char f;//1
        public char g;//1
        public int h;//4
    };
}

输出结果

结构体大小:16

 

转载 https://blog.csdn.net/jueduiwudi6/article/details/80721108

 

上一篇:WebBrowser获取完整的Cookie


下一篇:VC++ 并行库效率测试