There is a sizeof
operator. However, it can only be used in an unsafe context.
There is also a difference in the method proposed by Mehrdad, naming:
For all other types, including structures, the sizeof operator can only be used in insecure blocks of code. Although you can use the Marshal.SizeOf method, the value returned by this method does not always match the value returned by sizeof. Marshal.SizeOf returns the size after the type has been marshaled, while sizeof returns the size since it was allocated by the common language environment, including any addition.
a source
Example:
unsafe { int size = sizeof(MyStruct)*myArray.Length; }
source share