of the evaluation stack, there is no need for any effort here—the string is
already on the stack, and it is going to be passed on to the constructor. Once the
constructor returns newobjplaces a reference to the newly constructed object
at the top of the stack, and the next line pops that reference from the stack into
V_2, which was originally defined as a StringItem.
The next sequence loads the values of V_0and V_2into the stack and calls
LinkedList::AddItem(class ListItem). The use of the callvirt
instruction indicates that this is a virtual method, which means that the spe-
cific method will be determined in runtime, depending on the specific type of
the object on which the method is invoked. The first parameter being passed to
this function is V_2, which is the StringItemvariable. This is the object
instance for the method that’s about to be called. The second parameter, V_0,
is the ListItemparameter the method takes as input. Passing an object
instance as the first parameter when calling a class member is a standard prac-
tice in object-oriented languages. If you’re wondering about the implementa-
tion of the AddItem member, I’ll discuss that later, but first, let’s finish
investigating the current method.
The sequence at IL_0027is one that you’ve seen before: It essentially incre-
ments V_1by one and stores the result back into V_1. After that you reach the
end of the loop, which you’ve already analyzed. Once the conditional jump is
not taken (once V_1is greater than 10), the code calls LinkedList::Dump()
on our LinkedListobject from V_0.
Let’s summarize what you’ve seen so far in the program’s entry point,
before I start analyzing the individual objects and methods. You have a pro-
gram that instantiates a LinkedListobject, and loops 10 times through a
sequence that constructs the string “ItemX”, where Xis the current value of
our iterator. This string then is passed to the constructor of a StringItem
object. That StringItemobject is passed to the LinkedListobject using the
AddItemmember. This is clearly the process of constructing a linked list item
that contains your string and then adding that item to the main linked list
object. Once the loop is completed the Dumpmethod in the LinkedList
object is called, which, you can only assume, dumps the entire linked list in
some way.
The ListItem Class
At this point you can take a quick look at the other objects that are defined in
this program and examine their implementations. Let’s start with the List
Itemclass, whose entire definition is given in Listing 12.3.
438 Chapter 12