I'm initializing an integer variable like this:
LocalBuilder a = ilGen.DeclareLocal(typeof(Int32));
How can I access it and assign a value to it? I want to do something like this:
int a, b;
a = 5;
b = 6;
return a + b;
I'm initializing an integer variable like this:
LocalBuilder a = ilGen.DeclareLocal(typeof(Int32));
How can I access it and assign a value to it? I want to do something like this:
int a, b;
a = 5;
b = 6;
return a + b;
Use the
Ldloc
andStloc
opcodes to read and write local variables:Note that the C# compiler uses the shorthand form of some of the opcodes (via .NET Reflector):