Root Question Message
AddStrings(ref strings, GetStrings());
void AddStrings(ref List<string> list, IEnumerable<string> toAdd)
list = before.ToList()is an unnecessary assignment.
refto a reference type either, can someone explain?
foo = "asdasd", you are not modifying the string. You are creating a new string altogether. Not sure about
ref List, though.
ref stringis required when a string is a reference type?
ref strings, as in, a variable named
stringsbeing passed as
ref Listwould be needed. I don't see how this would "pass by value" if it's a reference. Can you only change the actual items in the list, but you can't change the list itself unless you add
stringsis passed as ref. Then in the method, you are adding stuff to
list, meaning you are adding stuff to
strings. But then you are killing the original ref for
list = before.ToString().
stringswill still be a list with 5 elements, while list, now only in the scope of the function itself, only has 2 elements.
ref. Because you don't wanna have another reference, when you are reassigning
stringsin the original code, is passed by value, it's reference is evaluated and a copy is generated, you can do whatever you want with that copy, it's an exact copy of
stringsbut only with the existing references, so new references are not part of the original object, so you either return the result and assign it or you do everything by ref
stringsis gone. I just worded poorly. mb