Lazy<T>.IsValueCreated 属性

定义

获取一个值,该值表示是否为该 Lazy<T> 实例创建了值。Gets a value that indicates whether a value has been created for this Lazy<T> instance.

public:
 property bool IsValueCreated { bool get(); };
public bool IsValueCreated { get; }
member this.IsValueCreated : bool
Public ReadOnly Property IsValueCreated As Boolean

属性值

Boolean

如果为此 Lazy<T> 实例创建了值,则为 true;否则为 falsetrue if a value has been created for this Lazy<T> instance; otherwise, false.

注解

当实例发生延迟初始化时 Lazy<T> ,可能会导致创建值或引发异常。When lazy initialization occurs for a Lazy<T> instance, it may result in either a value being created or an exception being thrown. 如果引发异常,则实例的后续行为 Lazy<T> 取决于异常缓存是否生效。If an exception is thrown, subsequent behavior of the Lazy<T> instance depends on whether exception caching is in effect. 如果该 Lazy<T> 实例是使用未指定初始化函数的构造函数创建的,则异常缓存将不起作用。If the Lazy<T> instance was created by using a constructor that does not specify an initialization function, then exception caching is not in effect. 再次尝试初始化 Lazy<T> 可能会成功,并且在成功初始化后, IsValueCreated 属性将返回 trueA subsequent attempt to initialize the Lazy<T> might succeed, and after successful initialization the IsValueCreated property returns true. 如果 Lazy<T> 实例是使用) 构造函数的参数指定 (指定的初始化函数创建的 valueFactory Lazy<T> ,则异常缓存由线程安全模式控制。If the Lazy<T> instance was created with an initialization function (specified by the valueFactory parameter of the Lazy<T> constructor), then exception caching is controlled by the thread safety mode.

适用于

另请参阅