Redigera

Dela via


Unsafe.SizeOf<T> Method

Definition

Returns the size of a value of the given type parameter.

public:
generic <typename T>
 static int SizeOf();
public static int SizeOf<T> ();
static member SizeOf : unit -> int
Public Shared Function SizeOf(Of T) () As Integer

Type Parameters

T

The type whose size is to be retrieved.

Returns

The size, in bytes, of a value of type T.

Remarks

This API corresponds to the sizeof opcode. If T is a reference type, the return value is the size of the reference itself (equal to sizeof(void*)). See ECMA-335, Sec. III.4.25 ("sizeof - load the size, in bytes, of a type") for more information.

Caution

This API returns the size of the managed view of the type. For the size of the unmanaged view of the type, such as needed for interop purposes, use SizeOf.

Applies to