如何找到一类在C#中的大小

问题描述:

public class A
{
  int x;
  float y;
}



如何找到类在C#中的大小。
是否有与sizeof(),它用来在C任何运营商++

How to find the size of the class in C#. Is there any operator like Sizeof(), which used to be in C++

简短的回答:

您不要

龙答:

您只能做,如果你输入有一个固定的布局,也没有管理人员。结构默认情况下,固定的。类可以归因于有固定的布局。

You can only do that if you type has a fixed layout and has no managed members. Structs are fixed by default. Classes can attributed to have a fixed layout.

(我不显示怎么样,因为你真的不需要它。互做时,它是唯一重要的。)

(I am not showing how, as you really do not need it. It is only important when doing interop.)