C#: When adding the same object to two List<object> variables, is the object cloned in the process?

后端 未结 7 1149
伪装坚强ぢ
伪装坚强ぢ 2021-01-01 19:28

I have something similar to this:

// Declarations:
List list1 = new List();
List list2 = new List

        
7条回答
  •  天命终不由人
    2021-01-01 20:13

    You're replacing the reference in one list with a reference to a new object. If you were to instead change a property of that object, you would see it changed in both places, since the reference would remain the same.

提交回复
热议问题