Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / June 2003

Tip: Looking for answers? Try searching our database.

IL coding question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Antonio Linares - 30 Jun 2003 11:00 GMT
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
Gabriele G. Ponti - 30 Jun 2003 13:25 GMT
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

> I am curretly porting an open source language www.harbour-project.org to
> .NET.
[quoted text clipped - 22 lines]
>
> Antonio
Antonio Linares - 30 Jun 2003 15:05 GMT
Gabriele,

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

regards,

Antonio

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.