When I set a new list equal to another list, does it set the new list as a pointer to the other list or is it actually creating a new list?
For example,
Is...
List<SomeType> newList = oldList;
...the same as...
List<SomeType> newList = new List<SomeType>();
newList.AddRange(oldList);
(oldList is a list of SomeType as well)?
There will be one List
and multiple references to it. This applies for all reference types (classes).
Value types (structs), on the other hand, are copied when assigned.
The assignment operator is not a cloning operator. In case of reference types, it copies values of references.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With