Lazy<(Of <(T>)>) Class

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Provides support for lazy initialization.

Inheritance Hierarchy

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

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

Syntax

Public Class Lazy(Of T)
public class Lazy<T>

Type Parameters

  • T
    Specifies the type of object that is being lazily initialized.

The Lazy<(Of <(T>)>) type exposes the following members.

Constructors

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

Top

Properties

  Name Description
IsValueCreated Gets a value that indicates whether a value has been created for this Lazy<(Of <(T>)>) instance.
Value Gets the lazily initialized value of the current Lazy<(Of <(T>)>) instance.

Top

Methods

  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 the Object 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<(Of <(T>)>)..::.Value property for this instance. (Overrides Object..::.ToString()()().)

Top

Remarks

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

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.

Version Information

Windows Phone OS

Supported in: 8.1, 8.0

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.

See Also

Reference

System Namespace