Lazy<T> Class
[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]
Provides support for lazy initialization.
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
The Lazy<T> type exposes the following members.
| Name | Description | |
|---|---|---|
|
Lazy<T>() | Initializes a new instance of the Lazy<T> class. When lazy initialization occurs, the default constructor of the target type is used. |
|
Lazy<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. |
|
Lazy<T>(Func<T>) | Initializes a new instance of the Lazy<T> class. When lazy initialization occurs, the specified initialization function is used. |
|
Lazy<T>(LazyThreadSafetyMode) | Initializes a new instance of the Lazy<T> class that uses the default constructor of T and the specified thread-safety mode. |
|
Lazy<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. |
|
Lazy<T>(Func<T>, LazyThreadSafetyMode) | Initializes a new instance of the Lazy<T> class that uses the specified initialization function and thread-safety mode. |
| Name | Description | |
|---|---|---|
|
IsValueCreated | Gets a value that indicates whether a value has been created for this Lazy<T> instance. |
|
Value | Gets the lazily initialized value of the current Lazy<T> instance. |
| Name | Description | |
|---|---|---|
|
Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
|
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
|
GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
|
GetType | Gets the Type of the current instance. (Inherited from Object.) |
|
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
|
ToString | Creates and returns a string representation of the Lazy<T>.Value property for this instance. (Overrides Object.ToString().) |
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.
Note
|
|---|
|
The HostProtectionAttribute attribute applied to this type or member has the following Resources property value: Synchronization | ExternalThreading. The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes. |
Windows 8 Consumer Preview, Windows Server 8 Beta, Windows 7, Windows Server 2008 SP2, Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Note