Groups | Blog | Home
all groups > dotnet clr > june 2003 >

dotnet clr : IL coding question


Gabriele G. Ponti
6/30/2003 8:25:24 AM
Antonio,

One of the constructors of the ArrayList class accepts an ICollection as
parameter. Stack is a class that implements the ICollection interface. So
what I am suggesting here is to use a temporary class to push your objects,
and then create the ArrayList from the stack.

..locals init ([0] class [mscorlib]System.Collections.Stack stack,
[1] class [mscorlib]System.Collections.ArrayList arraylist)
newobj instance void [mscorlib]System.Collections.Stack::.ctor()
stloc.0
ldloc.0
ldc.i4.s 123
box [mscorlib]System.Int32
callvirt instance void
[mscorlib]System.Collections.Stack::Push(object)
ldloc.0
ldc.i4 456
box [mscorlib]System.Int32
callvirt instance void
[mscorlib]System.Collections.Stack::Push(object)
ldloc.0
newobj instance void
[mscorlib]System.Collections.ArrayList::.ctor(class [mscorlib]
System.Collections.ICollection)
stloc.1

Maybe having a temporary variable is not the most elegant solution, but it
is something that VB.NET and C# compilers often do.

Gabriele

[quoted text, click to view]

Antonio Linares
6/30/2003 12:00:44 PM
I am curretly porting an open source language www.harbour-project.org to
..NET.

I have the following IL coding question, hopefully someone may provide me
some guidance:

I have some objects ("object" type) placed at the stack. Then I need to
create an ArrayList and pop those objects from the stack and add them to the
array. i.e.:

ldc.i4.s 123
box [mscorlib]System.Int32
ldc.i4.s 456
box [mscorlib]System.Int32
call object ObjArrayGen( int32 ) // I do know how many objects are
placed at the stack

The question is how could I pop those objects from the stack and add them to
a new created ArrayList from inside ObjArrayGen() ? I can't create a
object[] in advance (I already considered such way).

thanks!

Please remove REMOVE_THIS from my address to answer me directly.

Antonio

Antonio Linares
6/30/2003 4:05:44 PM
Gabriele,

Thanks for your suggestion, but I got it working using Mattias advice,

regards,

Antonio

AddThis Social Bookmark Button