Layout of .NET value type in memory

前端 未结 3 1548
滥情空心
滥情空心 2021-01-01 23:03

I have the following .NET value types:

[StructLayout(LayoutKind.Sequential)]
public struct Date
{
    public UInt16 V;
}

[StructLayout(LayoutKind.Sequential         


        
3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-01 23:51

    If you need explicit layout... use explicit layout...

    [StructLayout(LayoutKind.Explicit)]
    public struct StringPair
    {
        [FieldOffset(0)] public String A;
        [FieldOffset(8)] public String B;
        [FieldOffset(16)] public String C;
        [FieldOffset(24)] public Date D;
        [FieldOffset(32)] public double V;
    }
    

提交回复
热议问题