How to find the size of a class in C#
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++ Short answer: You dont. Long answer: 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.) Ritesh The following would give you the size of the C# class: Marshal.SizeOf(typeof(Myclass)); using System.Runtime.InteropServices; [StructLayout(LayoutKind.Sequential)]