这是让我印象深刻的事情,我想知道这是否可能。
长话短说 - 这是代码:
public class NotificationCollection : ObservableCollection<Notification>
{
public NotificationCollection() : base()
{
this.CollectionChanged += NotificationCollection_CollectionChanged;
this.PropertyChanged += NotificationCollection_PropertyChanged;
}
public NotificationCollection(IEnumerable<Notification> items)
: base(items)
{
this.CollectionChanged += NotificationCollection_CollectionChanged;
this.PropertyChanged += NotificationCollection_PropertyChanged;
}
(....)
}
如您所见,我正在复制代码。如果我没有创建一个继承的类,我会写
public NotificationCollection(IEnumerable<Notification> items)
: this() //I can just call the empty constructor
{
//do stuff here...
//however, in case of inheritance this would be handled by base(items)
}
所以,我的问题是——我可以同时调用base
类构造函数和this
构造函数吗?