1
public class MyBindingList : BindingList<int>
        {
            public MyBindingList()
            {
            }
            private BindingList<int> temp;
            public void Backup()
            {
                int[] arr = new int[this.Count];
                this.CopyTo(arr,0);
                temp = new BindingList<int>(arr);
            }
            public void Restore()
            {
                this.Items.Clear();
                //for(int i=0;i<temp.Count;i++) this.Add(temp[i]);
            }
        }

//for(int i=0;i<temp.Count;i++) this.Add(temp[i]);

是一种如此缓慢的恢复方式,那么我可以使用什么来更有效地恢复()?

4

1 回答 1

1

以您的示例为例, foreach 是最简单,最快捷的方法。

更快的方法是通过复制构造函数。但是,对于您的示例,它将不起作用。你不能说这=新...

myList = new BindingList<int>(temp);

编辑:旁注,您可以通过删除数组的创建来清理 Backup() 并调用:

public void Backup()
{
    this.temp = new BindingList<int>(this);
}
于 2011-02-27T19:27:43.727 回答