<分区>
Possible Duplicate:
How to check the number of bytes consumed by my Structure?
我有一个打包形式的结构
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct test
{
public int a;
public uint16 b;
}
当编译器声明 sizeof 只能在不安全的上下文中使用时,我如何获取结构的大小?
标签 c#
<分区>
Possible Duplicate:
How to check the number of bytes consumed by my Structure?
我有一个打包形式的结构
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct test
{
public int a;
public uint16 b;
}
当编译器声明 sizeof 只能在不安全的上下文中使用时,我如何获取结构的大小?
最佳答案
SizeOf
方法可以解决问题。
int size = System.Runtime.InteropServices.Marshal.SizeOf(typeof(Point));
关于c# - 在 C# 中获取结构的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4956435/