ILGenerator::DeclareLocal Method (Type^)
Declares a local variable of the specified type.
Assembly: mscorlib (in mscorlib.dll)
Parameters
- localType
-
Type:
System::Type^
A Type object that represents the type of the 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 );
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.1