Unsafe.SizeOf<T> Method

Definition

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

public static int SizeOf<T> ();

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.

Застереження

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

Продукт Версії
.NET Core 1.0, Core 1.1, Core 3.0, Core 3.1, 5, 6 (package-provided), 6, 7, 8, 9
.NET Standard 2.0 (package-provided)