語言

Marshal.SizeOf 方法

定義

回傳類別的未管理大小(位元組)。

多載

名稱 Description
SizeOf(Object)
已淘汰.

回傳物件的未管理大小(以位元組為單位)。

SizeOf(Type)
已淘汰.

回傳未受管理型態的大小(位元組)。

SizeOf<T>()

回傳未受管理型態的大小(位元組)。

SizeOf<T>(T)

回傳指定型別物件的未管理大小(位元組)。

SizeOf(Object)

來源:
Marshal.cs
來源:
Marshal.cs
來源:
Marshal.cs
來源:
Marshal.cs
來源:
Marshal.cs

警告

SizeOf(Object) may be unavailable in future releases. Instead, use SizeOf<T>(). For more info, go to http://go.microsoft.com/fwlink/?LinkID=296514

回傳物件的未管理大小(以位元組為單位)。

public:
 static int SizeOf(System::Object ^ structure);
[System.Obsolete("SizeOf(Object) may be unavailable in future releases. Instead, use SizeOf<T>(). For more info, go to http://go.microsoft.com/fwlink/?LinkID=296514")]
public static int SizeOf(object structure);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Marshalling code for the object might not be available. Use the SizeOf<T> overload instead.")]
public static int SizeOf(object structure);
public static int SizeOf(object structure);
[System.Runtime.InteropServices.ComVisible(true)]
public static int SizeOf(object structure);
[<System.Obsolete("SizeOf(Object) may be unavailable in future releases. Instead, use SizeOf<T>(). For more info, go to http://go.microsoft.com/fwlink/?LinkID=296514")>]
static member SizeOf : obj -> int
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Marshalling code for the object might not be available. Use the SizeOf<T> overload instead.")>]
static member SizeOf : obj -> int
static member SizeOf : obj -> int
[<System.Runtime.InteropServices.ComVisible(true)>]
static member SizeOf : obj -> int
Public Shared Function SizeOf (structure As Object) As Integer

參數

structure
Object

要回傳大小的物件。

傳回

在非管理程式碼中,指定物件的大小。

屬性

例外狀況

參數 structure 為 null。

備註

此方法接受結構的實例,結構可為參考型別或框框值型別。 版面必須是順序性或明確的。

回傳的大小就是未管理物件的大小。 物件的未管理大小與管理大小可能不同。 對於角色類型,大小會受到 CharSet 該類別所施加的值影響。

你可以用這個 SizeOf 方法來判斷要分配多少未管理記憶體,並用 AllocHGlobal and AllocCoTaskMem 方法。

另請參閱

適用於

SizeOf(Type)

來源:
Marshal.cs
來源:
Marshal.cs
來源:
Marshal.cs
來源:
Marshal.cs
來源:
Marshal.cs

警告

SizeOf(Type) may be unavailable in future releases. Instead, use SizeOf<T>(). For more info, go to http://go.microsoft.com/fwlink/?LinkID=296515

回傳未受管理型態的大小(位元組)。

public:
 static int SizeOf(Type ^ t);
[System.Obsolete("SizeOf(Type) may be unavailable in future releases. Instead, use SizeOf<T>(). For more info, go to http://go.microsoft.com/fwlink/?LinkID=296515")]
public static int SizeOf(Type t);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Marshalling code for the object might not be available. Use the SizeOf<T> overload instead.")]
public static int SizeOf(Type t);
public static int SizeOf(Type t);
[<System.Obsolete("SizeOf(Type) may be unavailable in future releases. Instead, use SizeOf<T>(). For more info, go to http://go.microsoft.com/fwlink/?LinkID=296515")>]
static member SizeOf : Type -> int
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Marshalling code for the object might not be available. Use the SizeOf<T> overload instead.")>]
static member SizeOf : Type -> int
static member SizeOf : Type -> int
Public Shared Function SizeOf (t As Type) As Integer

參數

t
Type

要回傳的大小類型。

傳回

在非管理程式碼中,指定型別的大小。

屬性

例外狀況

參數 t 為一般型別定義。

參數 t 為 null。

備註

當你沒有固定結構時,也可以用這個方法。 版面必須是順序性或明確的。

回傳的大小即為未管理型態的大小。 物件的未管理大小與管理大小可能不同。 對於角色類型,大小會受到 CharSet 該類別所施加的值影響。

另請參閱

適用於

SizeOf<T>()

來源:
Marshal.cs
來源:
Marshal.cs
來源:
Marshal.cs
來源:
Marshal.cs
來源:
Marshal.cs

回傳未受管理型態的大小(位元組)。

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

類型參數

T

要回傳的大小類型。

傳回

以位元組為單位,指由 T 一般型別參數指定的型態大小。

備註

當你沒有固定結構時,也可以用這個方法。 版面必須是順序性或明確的。

回傳的大小即為未管理型態的大小。 物件的未管理大小與管理大小可能不同。 對於角色類型,大小會受到 CharSet 該類別所施加的值影響。

適用於

SizeOf<T>(T)

來源:
Marshal.cs
來源:
Marshal.cs
來源:
Marshal.cs
來源:
Marshal.cs
來源:
Marshal.cs

回傳指定型別物件的未管理大小(位元組)。

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

類型參數

T

參數的 structure 類型。

參數

structure
T

要回傳大小的物件。

傳回

在非管理程式碼中,指定物件的大小(以位元組為單位)。

例外狀況

參數 structure 為 null。

備註

此方法接受結構的實例,結構可為參考型別或框框值型別。 版面必須是順序性或明確的。

回傳的大小就是未管理物件的大小。 物件的未管理大小與管理大小可能不同。 對於角色類型,大小會受到 CharSet 該類別所施加的值影響。

你可以用這個 SizeOf<T>(T) 方法來判斷要分配多少未管理記憶體,方法是用 AllocHGlobal and AllocCoTaskMem 方法。

適用於