Method GetManagedSize
GetManagedSize(Type)
Get the managed size of a given type. This matches an IL-level sizeof(t), even if it cannot be determined normally in C#.
Note that
sizeof(t) != Marshal.SizeOf(t)
, f.e. when t is char.public static int GetManagedSize(this Type t)
Parameters
t
Type- The type to get the size from.
Returns
- int
- The managed type size.
Remarks
An IL-level
sizeof(t)
will return sizeof(IntPtr)
for reference types, as it refers to the size on stack or in an object,
not the size on heap.