1
時,我有以下代碼:是分離和reattching需要事件設置的BindingList
private BindingList<Box> _boxesToDisplay;
public BindingList<Box> BoxesToDisplay
{
get
{
return _boxesToDisplay;
}
set
{
// Unhook the old one. Just incase
_boxesToDisplay.AddingNew -= NewItemAdded;
// Set the new value
_boxesToDisplay = value;
// Hook in the value again.
_boxesToDisplay.AddingNew += NewItemAdded;
}
}
但我開始思考。如果這對於運營商來說是一個超負荷的情況,那將是最好的。然後我想知道他們是否真的這樣做,我可以用這個代替我的代碼:
public BindingList<Box> BoxesToDisplay { get; set; }
是真的嗎?這會:
myClass.BoxesToDisplay = new BindingList<Box>();
仍然有AddingNew
事件設置爲NewItemAdded()
與BoxesToDisplay
要麼定義是什麼?