How to copy List in C#

后端 未结 1 1741
慢半拍i
慢半拍i 2021-01-19 23:38

I want to copy a List of Objects, but i keep getting references between the objects.

List copy = original;

When i change the

相关标签:
1条回答
  • 2021-01-20 00:38

    You can do this:

    List<MyClass> copy = original.ToList();
    

    This would make an element-by-element copy of the list, rather than copying the reference to the list itself.

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