如何找到一类在C#中的大小 [英] How to find the size of a class in C#

查看:168
本文介绍了如何找到一类在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.)

这篇关于如何找到一类在C#中的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆