c# - 在 C# 中获取结构的大小

标签 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/

相关文章:

c# - 使用不区分大小写的参数 API Mikrotik tik4net 读取数据

c# - 将 Windows 10 UWP WebAccountManager 与 Google OAuth 或 MSA 结合使用

c# - Sprite 变得模糊

c# - 如何获取类的枚举属性列表?

c# - System.Data.SQLite 不支持多事务

c# - C#中的FNT字体文件

c# - C#中的这个RC4加密代码有什么问题吗

c# - 如何将报告从 Microsoft.Reporting.WinForms.ReportViewer v11 导出到 .xls 文件

c# - 从对象数组中删除重复项

c# - 类似 Internet Explorer 收藏夹窗口的弹出窗口