System Namespace


.NET Framework Class Library
Lazy<(Of <(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)
Syntax

Visual Basic (Declaration)
<SerializableAttribute> _
<ComVisibleAttribute(False)> _
<HostProtectionAttribute(SecurityAction.LinkDemand, Synchronization := True,  _
    ExternalThreading := True)> _
Public Class Lazy(Of T)
Visual Basic (Usage)
Dim instance As Lazy(Of T)
C#
[SerializableAttribute]
[ComVisibleAttribute(false)]
[HostProtectionAttribute(SecurityAction.LinkDemand, Synchronization = true, 
    ExternalThreading = true)]
public class Lazy<T>
Visual C++
[SerializableAttribute]
[ComVisibleAttribute(false)]
[HostProtectionAttribute(SecurityAction::LinkDemand, Synchronization = true, 
    ExternalThreading = true)]
generic<typename T>
public ref class Lazy
F#
[<SerializableAttribute>]
[<ComVisibleAttribute(false)>]
[<HostProtectionAttribute(SecurityAction.LinkDemand, Synchronization = true, 
    ExternalThreading = true)>]
type Lazy<'T> =  class end

Type Parameters

T

Specifies the type of object that is being lazily initialized.

Remarks

NoteNote

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.

Lazy initialization occurs the first time the Lazy<(Of <(T>)>)..::.Value property is accessed or the Lazy<(Of <(T>)>)..::.ToString method is called.

Use an instance of Lazy<(Of <(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.

Inheritance Hierarchy

System..::.Object
  System..::.Lazy<(Of <(T>)>)
    System..::.Lazy<(Of <(T, TMetadata>)>)
Thread Safety

By default, all public and protected members of the Lazy<(Of <(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.

Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 4

.NET Framework Client Profile

Supported in: 4
See Also

Reference

Other Resources

Page view tracker