I was wondering, and i’m not really sure, but help me out here.
If you have a List items, and there’s one object you need to change a property of it.
Say myClass has a string property “status”. I’m searching my list with a for-loop and i get my object so i do
myClass item = items[i];
if i want to change the “status” property, i do this for example :
item.Status = "new status";
My question/issue is this: is “item” still linked to the list item, so that if i execute the line above, it will be changed in the list as well without having to set this :
items[i] = item;
Hope this is clear.
Thanks in advance.
The code
item.Status = "new status";will change the list itemitems[i]points to a myClass object.When you say
myClass item = items[i];, it is referenced by bothitemanditems[i].so when you alter one of the properties like this
item.Status = "new status";you’re actually making changes to your myClass object which now has two namesitemanditems[i].You can also use
item[i].Status = "new status";. Both do the same job.Setting
items[i] = item;has no effect, since both reference the same object already.