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++
The size of an empty class is not zero. It is 1 byte generally. It is nonzero to ensure that the two different objects will have different addresses.
The size of object of a class depends on the no. of bytes occupied by the data members of the class. }; The object of class student will occupy space of 8 bytes.
The following would give you the size of the C# class:
Marshal.SizeOf(typeof(Myclass)); using System.Runtime.InteropServices; [StructLayout(LayoutKind.Sequential)] class Myclass { }
Remember size of a class depends on padding.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With