共用方式為


WeakReference 建構函式

定義

初始化 WeakReference 類別的新執行個體。

多載

WeakReference(Object)

參考指定的物件,初始化 WeakReference 類別的新執行個體。

WeakReference(Object, Boolean)

參考指定的物件,並使用指定的重新恢復狀態追蹤,初始化 WeakReference 類別的新執行個體。

WeakReference(SerializationInfo, StreamingContext)
已淘汰.

使用指定序列化和資料流物件的還原序列化資料,來初始化 WeakReference 類別的新執行個體。

WeakReference(Object)

來源:
WeakReference.cs
來源:
WeakReference.cs
來源:
WeakReference.cs

參考指定的物件,初始化 WeakReference 類別的新執行個體。

public:
 WeakReference(System::Object ^ target);
public WeakReference (object target);
public WeakReference (object? target);
new WeakReference : obj -> WeakReference
Public Sub New (target As Object)

參數

target
Object

要追蹤的物件或 null

備註

此建構函式會建立 的簡短弱式參考 target

另請參閱

適用於

WeakReference(Object, Boolean)

來源:
WeakReference.cs
來源:
WeakReference.cs
來源:
WeakReference.cs

參考指定的物件,並使用指定的重新恢復狀態追蹤,初始化 WeakReference 類別的新執行個體。

public:
 WeakReference(System::Object ^ target, bool trackResurrection);
public WeakReference (object target, bool trackResurrection);
public WeakReference (object? target, bool trackResurrection);
new WeakReference : obj * bool -> WeakReference
Public Sub New (target As Object, trackResurrection As Boolean)

參數

target
Object

要追蹤的物件。

trackResurrection
Boolean

指示何時停止追蹤物件。 如果為 true,則會在結束之後追蹤物件;如果為 false,則只會追蹤物件到結束為止。

範例

下列範例會建立具有簡短弱式參考的資料物件的快取。 此範例是針對 類別提供的較大範例的 WeakReference 一部分。

 // Add objects with a short weak reference to the cache.
for (int i = 0; i < count; i++) {
     _cache.Add(i, new WeakReference(new Data(i), false));
 }
// Add objects with a short weak reference to the cache.
for i = 0 to count - 1 do
    _cache.Add(i, WeakReference(Data i, false))
' Add data objects with a short weak reference to the cache. 
For ctr = 0 To count - 1
    _cache.Add(ctr, New WeakReference(New Data(ctr)))
Next

備註

如果 為 trackResurrectionfalse ,則會建立簡短弱式參考。 如果 為 trackResurrectiontrue ,則會建立長弱式參考。

另請參閱

適用於

WeakReference(SerializationInfo, StreamingContext)

來源:
WeakReference.cs
來源:
WeakReference.cs
來源:
WeakReference.cs

警告

This API supports obsolete formatter-based serialization. It should not be called or extended by application code.

使用指定序列化和資料流物件的還原序列化資料,來初始化 WeakReference 類別的新執行個體。

protected:
 WeakReference(System::Runtime::Serialization::SerializationInfo ^ info, System::Runtime::Serialization::StreamingContext context);
protected WeakReference (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
[System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
protected WeakReference (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
new WeakReference : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> WeakReference
[<System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
new WeakReference : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> WeakReference
Protected Sub New (info As SerializationInfo, context As StreamingContext)

參數

info
SerializationInfo

保有序列化或還原序列化目前 WeakReference 物件所需之所有資料的物件。

context
StreamingContext

(保留的) 說明 info 所指定的序列化資料流之來源和目的端。

屬性

例外狀況

infonull

備註

參數 context 是保留的,目前未參與這項作業。

適用於