c# - Generic list and value reference -
i have 2 object's let's call them a
, b
, method
list<b> dosomething(ref a, list<b> b) { list<b> newlist = new list<b>(); // //doing ref // foreach(var elementofb in b.where(...)) { // elementofb.name = "..."; // newlist.add(elementofb); } return newlist; }
so, after method done original list b
have changed value name
field (string
) did not pass ref
, i'm using where
should return copy of elemens right? question why list b
changed it's values?
list<b> originallist = ...; list<b> newlist = dosomething(ref a, originallist); //now originallist have changed name field values
actually list<b>
list of reference b elements. list of reference changed, references still point same objects.
if clone object need, take @ topic.
Comments
Post a Comment