Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

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

.NET Framework (current version)
 

Initializes a target reference or value type with its default constructor if it hasn't already been initialized.

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

public:
generic<typename T>
static T EnsureInitialized(
	T% target,
	bool% initialized,
	Object^% syncLock
)

Parameters

target
Type: T%

A reference or value of type T to initialize if it hasn't already been initialized.

initialized
Type: System::Boolean%

A reference to a Boolean value 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, a new object will be instantiated.

Return Value

Type: T

The initialized value of type T.

Type Parameters

T

The type of the reference to be initialized.

Exception Condition
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.

Universal Windows Platform
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
Return to top
Show:
© 2017 Microsoft