C#复制绑定列表的最佳方法是什么? [英] C# What is the best way to copy a BindingList?
本文介绍了C#复制绑定列表的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
复制BindingList的最佳方法是什么?
What is the best way to copy a BindingList?
只使用ForEach()吗?还是有更好的方法?
Just use ForEach()? Or are there better ways?
推荐答案
BindingList有一个可以接受IList的构造函数。 BindingList实现IList。因此,您可以执行以下操作:
BindingList has a constructor which can take an IList. And BindingList implements IList. So you can just do the following:
BindingList newBL = new BindingList(oldBL);
当然会创建第二个列表,该列表仅指向相同的对象 。如果您确实想克隆列表中的对象,则必须做更多的工作。
Of course that creates a second list that just points at the same objects. If you actually want to clone the objects in the list then you have to do more work.
这篇关于C#复制绑定列表的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文