L
luke
I have a class 'item' and I want to create an array of these items.
like this
ArrayList items = new ArrayList();
while (reader.read())
{
item i = new item(Convert.ToString(reader[0]));
items.Add(i);
}
But the address of item (&item) is the same for each pass of the
loop. Consequentially every reference in the array is the same and
every item in my array displays the value of the last item set - which
makes sense considering all the references point to the same memory
location. Ideally I'd like to have an array of unique items. How do
I get a fresh instance on each pass of the loop?
Maybe I haven't had sleep enough? Usually I program in C++.
TIA
Luke
like this
ArrayList items = new ArrayList();
while (reader.read())
{
item i = new item(Convert.ToString(reader[0]));
items.Add(i);
}
But the address of item (&item) is the same for each pass of the
loop. Consequentially every reference in the array is the same and
every item in my array displays the value of the last item set - which
makes sense considering all the references point to the same memory
location. Ideally I'd like to have an array of unique items. How do
I get a fresh instance on each pass of the loop?
Maybe I haven't had sleep enough? Usually I program in C++.
TIA
Luke