获取结构的大小在C# [英] Get size of struct in C#
本文介绍了获取结构的大小在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:结果
的如何查看我的结构占用的字节数?
我在
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct test
{
public int a;
public uint16 b;
}
我如何获得该结构的大小,因为编译器的统计信息的sizeof能
How do I get the size of the struct as the compiler stats that sizeof can only be used in unsafe context?
感谢。
推荐答案
的 中SizeOf
方法的伎俩。
The SizeOf
method does the trick.
int size = System.Runtime.InteropServices.Marshal.SizeOf(typeof(Point));
这篇关于获取结构的大小在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文