How to find the size of a class in C#

前端 未结 5 626
一个人的身影
一个人的身影 2020-12-18 20:10
public class A
{
  int x;
  float y;
}

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

5条回答
  •  一个人的身影
    2020-12-18 20:47

    You could serialize the class into a memory stream and then get the size from there, but I wouldn't really recommend doing this unless you had to.

提交回复
热议问题