This documentation is archived and is not being maintained.

LazyInitializer.EnsureInitialized<T> Method (T%, Boolean%, Object%)

Initializes a target reference or value type with its default constructor if it has not already been initialized.

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

public static T EnsureInitialized<T>(
	ref T target,
	ref bool initialized,
	ref Object syncLock

Type Parameters


The type of the reference to be initialized.


Type: T%
A reference or value of type T to initialize if it has not already been initialized.
Type: System.Boolean%
A reference to a boolean that determines whether the target has already been initialized.
Type: System.Object%
A reference to an object used as the mutually exclusive lock for initializing target. If syncLock is null (Nothing in Visual Basic), a new object will be instantiated.

Return Value

Type: T
The initialized value of type T.


Permissions to access the constructor of type T were missing.


Type T does not have a default constructor.

If intialized is specified as true, then no further initialization occurs.

.NET Framework

Supported in: 4

.NET Framework Client Profile

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.