EN
Ce contenu n’est pas disponible dans votre langue. Voici la version anglaise.

Lazy<T> Class

May 11, 2014

Provides support for lazy initialization.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

public class Lazy<T>

Type Parameters

T

Specifies the type of object that is being lazily initialized.

The Lazy<T> type exposes the following members.

  NameDescription
Public methodLazy<T>()Initializes a new instance of the Lazy<T> class. When lazy initialization occurs, the default constructor of the target type is used.
Public methodLazy<T>(Boolean)Initializes a new instance of the Lazy<T> class. When lazy initialization occurs, the default constructor of the target type and the specified initialization mode are used.
Public methodLazy<T>(Func<T>)Initializes a new instance of the Lazy<T> class. When lazy initialization occurs, the specified initialization function is used.
Public methodLazy<T>(LazyThreadSafetyMode)Initializes a new instance of the Lazy<T> class that uses the default constructor of T and the specified thread safety mode.
Public methodLazy<T>(Func<T>, Boolean)Initializes a new instance of the Lazy<T> class. When lazy initialization occurs, the specified initialization function and initialization mode are used.
Public methodLazy<T>(Func<T>, LazyThreadSafetyMode)Initializes a new instance of the Lazy<T> class that uses the specified initialization function and thread safety mode.
Top

  NameDescription
Public propertyIsValueCreatedGets a value that indicates whether a value has been created for this Lazy<T> instance.
Public propertyValueGets the lazily initialized value of the current Lazy<T> instance.
Top

  NameDescription
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringCreates and returns a string representation of the Lazy<T>.Value property for this instance. (Overrides Object.ToString().)
Top

Lazy initialization occurs the first time the Lazy<T>.Value property is accessed.

Use an instance of Lazy<T> to defer the creation of a large or resource-intensive object or the execution of a resource-intensive task, particularly when such creation or execution might not occur during the lifetime of the program.

Windows Phone OS

Supported in: 8.1, 8.0

By default, all public and protected members of the Lazy<T> class are thread safe and may be used concurrently from multiple threads. These thread-safety guarantees may be removed optionally and per instance, using parameters to the type's constructors.

Afficher:
© 2014 Microsoft