Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想复制一个对象列表,但我不断获得对象之间的引用。
List<MyClass> copy = original;
当我更改副本列表中的值时,原始列表也最终被修改。有没有办法解决它?
你可以这样做:
List<MyClass> copy = original.ToList();
这将制作列表的逐个元素副本,而不是复制对列表本身的引用。