I have 2 object's let's call them A
, B
and method
List<B> DoSomething(ref A a, List<B> b)
{
List<B> newList = new List<B>();
//
//Doing something to ref A
//
foreach(var elementOfB in b.where(...))
{
//
elementOfB.Name = "...";
//
newList.Add(elementOfB);
}
return newList;
}
So, after that method is done my original list b
have changed value Name
field (string
) but I did not pass it as ref
and I'm using where
that should return copy of elemens right? So my question is why my list b
changed it's values?
List<B> originalList = ...;
List<B> newList = DoSomething(ref a, originalList);
//now originalList have changed Name field values