C# 结构体中结构体

x1xx12xxx123 2012-11-15 12:35:56

[StructLayout(LayoutKind.Sequential)]
public struct S1
{
public ulong Guid;
public uint X;
};

[StructLayout(LayoutKind.Sequential)]
public struct S11
{
public S1 s1;
public ulong Owner;
};

public S1 s1;这个如何定义,让其在S11中占用3个int32空间,就也是让s1是值类型,非引用类型,
最终Marshal.SizeOf(typeof(S11))能得到结构体大小为4个int32
...全文
77 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
bdmh 2012-11-15
  • 打赏
  • 举报
回复
struct是值类型,要想用引用类型,改成类
x1xx12xxx123 2012-11-15
  • 打赏
  • 举报
回复
最终Marshal.SizeOf(typeof(S11))能得到结构体大小为5个int32
x1xx12xxx123 2012-11-15
  • 打赏
  • 举报
回复
我的错,写错了
x1xx12xxx123 2012-11-15
  • 打赏
  • 举报
回复
Marshal.SizeOf(typeof(S1))正常 Marshal.SizeOf(typeof(S11))报错
x1xx12xxx123 2012-11-15
  • 打赏
  • 举报
回复
Marshal.SizeOf(typeof(S11)不怎么样,要用这能得到结构体大小,不能报错

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧