避免 N2 迭代

它放在 Windows 窗体事件处理程序中

var nameList = new BindingList<string>();
ComboBox1.DataSource = nameList;
for(long i = 0; i < 10000; i++ ) {
    nameList.AddRange(new [] {"Alice", "Bob", "Carol" });
} 

这需要很长时间来执行,修复,执行以下操作:

var nameList = new BindingList<string>();
ComboBox1.DataSource = nameList;
nameList.RaiseListChangedEvents = false;
for(long i = 0; i < 10000; i++ ) {
    nameList.AddRange(new [] {"Alice", "Bob", "Carol" });
} 
nameList.RaiseListChangedEvents = true;
nameList.ResetBindings();