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

后端 未结 7 1024
伪装坚强ぢ
伪装坚强ぢ 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:17

    Yes, you're not cloning the object. The object is being added to both lists originally by reference, and then subsequently you're assigned a reference in the list to the new object you're creating.

    That is definitely the expected result.

    0 讨论(0)
提交回复
热议问题