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]);

復元するのはとても遅い方法なので、restore()をより効率的に行うために何を使用できますか?

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 に答える