WeakReference 构造函数
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
初始化 WeakReference 类的新实例。
重载
WeakReference(Object) |
引用指定的对象初始化 WeakReference 类的新实例。 |
WeakReference(Object, Boolean) |
通过引用指定对象并使用指定的复活跟踪,初始化 WeakReference 类的新实例。 |
WeakReference(SerializationInfo, StreamingContext) |
已过时.
使用从指定的序列化和流对象反序列化的数据,初始化 WeakReference 类的新实例。 |
WeakReference(Object)
- Source:
- WeakReference.cs
- Source:
- WeakReference.cs
- Source:
- 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)
- Source:
- WeakReference.cs
- Source:
- WeakReference.cs
- Source:
- 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
注解
如果 trackResurrection
为 false
,则创建短弱引用。 如果 trackResurrection
为 true
,则创建一个长弱引用。
另请参阅
适用于
WeakReference(SerializationInfo, StreamingContext)
- Source:
- WeakReference.cs
- Source:
- WeakReference.cs
- Source:
- 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
指定的序列化流的源和目标。
- 属性
例外
info
上声明的默认值为 null
。
注解
参数 context
是保留的,当前不参与此操作。