copy bindinglist to another one

1.7k views Asked by At
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]);

is a so slowly way to restore, so what can i use for more efficiently restore()?

1

There are 1 answers

0
John Arlen On BEST ANSWER

With your example, foreach is the easiest and quickest way.

The faster way is via a copy-contructor. However with your example, it won't work. You can't say this = new ...

myList = new BindingList<int>(temp);

Edit: Side-comment, you can clean up Backup() by deleting the creation of the array and just call:

public void Backup()
{
    this.temp = new BindingList<int>(this);
}