Problem with adding items to lists
#2

U are trying to add the same class and just changed some values.

 

The values inside a class are passed by reference.

 

So lets say your class named Items. And u do this.

 

Items itemA = new Items();

itemA.id = 1;

 

Items itemB = itemA;

itemB.id = 2;

 

U would think that itemB is a copy of itemA with only a different id.

But its not. itemB is a reference to itemA. So everything u change in itemB gets changed in itemA aswell.

 

If u really want to make a copy lookup MemberwiseClone()



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)