LazyInitializer Class
Provides lazy initialization routines.
Assembly: mscorlib (in mscorlib.dll)
| Name | Description | |
|---|---|---|
![]() ![]() | EnsureInitialized<T>(T%) | Initializes a target reference type with the type's default constructor if it hasn't already been initialized. |
![]() ![]() | EnsureInitialized<T>(T%, Boolean%, Object^%) | Initializes a target reference or value type with its default constructor if it hasn't already been initialized. |
![]() ![]() | EnsureInitialized<T>(T%, Boolean%, Object^%, Func<T>^) | Initializes a target reference or value type by using a specified function if it hasn't already been initialized. |
![]() ![]() | EnsureInitialized<T>(T%, Func<T>^) | Initializes a target reference type by using a specified function if it hasn't already been initialized. |
These routines avoid needing to allocate a dedicated, lazy-initialization instance, instead using references to ensure targets have been initialized as they are accessed.
The following example demonstrates how to use EnsureInitialized to lazily initialize a value using a Boolean value to track whether initialization has already happened and an object to use as the mutual exclusion lock.
Available since 8
.NET Framework
Available since 4.0
Portable Class Library
Supported in: portable .NET platforms
Windows Phone Silverlight
Available since 8.0
Windows Phone
Available since 8.1
The methods of LazyInitializer are thread-safe and may be called from multiple threads concurrently.

