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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -