EnsureInitialized(T) Method (T, Boolean, Object)

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

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

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

T

The type of the reference to be initialized.

Parameters

target
Type: T %
A reference or value of type T to initialize if it has not already been initialized.
initialized
Type: System.Boolean %
A reference to a boolean that determines whether the target has already been initialized.
syncLock
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.

ExceptionCondition
MemberAccessException

Permissions to access the constructor of type T were missing.

MissingMemberException

Type T does not have a default constructor.

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

Windows Phone OS

Supported in: 8.1, 8.0

Show:
© 2017 Microsoft