0

i saw an implementation of an observable queue class here. I found two things i don't understand: 1. events, with the names PropertyChanged and CollectionChanged are already defined in the base class. Why you don't have to use 'new'?

public virtual event NotifyCollectionChangedEventHandler CollectionChanged;

2. the PropertyChanged event is declared in a simelar way to an property. Why do you do that?

 protected virtual event PropertyChangedEventHandler PropertyChanged;
 event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged
 {
    add { this.PropertyChanged += value; }
    remove { this.PropertyChanged -= value; }
 }
Community
  • 1
  • 1

2 Answers2

0

I can't see where in the base class where PropertyChanged and CollectionChanged are defined. It seems to me that these can be defined in ObservableStack<T> without the new keyword.

Also, the implementation of INotifyPropertyChanged.PropertyChanged event is being done explicitly so it must use the event accessor syntax, i.e. add and remove.

Enigmativity
  • 97,521
  • 11
  • 78
  • 153
  • Just had another look at the answer and you are right. Thought the base class is ObservableCollection. Thanks! –  Jun 25 '16 at 13:08
-1

That is the convention for event, events are merely a wrapper over delegates, so when you define an event you specify what kind of delegates would register for this event and then you can add or remove delegate registration this event.

Pharaoh
  • 622
  • 1
  • 6
  • 25