编程语言
首页 > 编程语言> > C#结构体大小问题

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

 

标签:Console,C#,System,char,大小,using,DataSize,public,结构
来源: https://www.cnblogs.com/zxtang/p/14412963.html