Problem with adding items to lists
#4

Try this

 

for(int i = 0; i

{

itemB = new Items();

itemB.ID = br.readInt32();

itemB.power = br.readInt32();

ItemA.Add(itemB);

}

 

 

The reason why it was happening is because of the reference. 

itemB stays the same when u dont initialize it again. 

And even if added to the list, itemB is still itemB.

So basically u just added 5x the same object to the list that all point to the same data.



Messages In This Thread
[No subject] - by soryjero - 09-20-2013, 11:10 PM
[No subject] - by Wizatek - 09-21-2013, 07:19 AM
[No subject] - by soryjero - 09-21-2013, 08:38 AM
[No subject] - by Wizatek - 09-21-2013, 09:14 AM
[No subject] - by soryjero - 09-21-2013, 10:28 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)