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.

ILGenerator::DeclareLocal Method (Type^)

 

Declares a local variable of the specified type.

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

public:
virtual LocalBuilder^ DeclareLocal(
	Type^ localType
)

Parameters

localType
Type: System::Type^

A Type object that represents the type of the local variable.

Return Value

Type: System.Reflection.Emit::LocalBuilder^

The declared local variable.

Exception Condition
ArgumentNullException

localType is null.

InvalidOperationException

The containing type has been created by the TypeBuilder::CreateType method.

The local variable is created in the current lexical scope; for example, if code is being emitted in a for loop (For loop in Visual Basic), the scope of the variable is the loop.

A local variable created with this overload is not pinned. To create a pinned variable for use with unmanaged pointers, use the DeclareLocal(Type^, Boolean) method overload.

The following code example demonstrates the use of the DeclareLocal method. This code is part of a larger code example for the LocalBuilder class.

// Create local variables named myString and myInt.
LocalBuilder^ myLB1 = myMethodIL->DeclareLocal( String::typeid );
myLB1->SetLocalSymInfo( "myString" );
Console::WriteLine( "local 'myString' type is: {0}", myLB1->LocalType );

LocalBuilder^ myLB2 = myMethodIL->DeclareLocal( int::typeid );
myLB2->SetLocalSymInfo( "myInt", 1, 2 );
Console::WriteLine( "local 'myInt' type is: {0}", myLB2->LocalType );

.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.1
Return to top
Show:
© 2017 Microsoft