我有一个MyClass的自定义Observable集合
class MyClass
{
}
class MyObservablECollection : ObservableCollection<MyClass>
{
}
现在我正在创建它们的对象:
ObservableCollection<MyClass> _varObsCollection = new ObservableCollection<MyClass>();
MyObservablECollection _varMyObservablECollection = new MyObservablECollection();
_varMyObservablECollection = _varObsCollection;
var _obsvleCollection = new ObservableCollection<MyCollection>(_myVar);
MyCollection _tempCollection = new ObservableCollection<MyCollection>(_myVar);
无法隐式转换类型&#39; System.Collections.ObjectModel.ObservableCollection&#39;到&#39; MyObservablECollection&#39;
我知道我们不能将父类对象(ObservableCollection<MyClass>
)分配给子类MyObservablECollection
但有没有办法可以施展它们?
答案 0 :(得分:-1)
你是颠倒了,这是工作案例:
ObservableCollection<MyClass> _tempCollection = new MyCollection(_myVar);
MyCollection
为ObservableCollection<MyCollection>
,但ObservableCollection<MyClass>
不一定是MyCollection
。
编辑:我知道您正在尝试维护相同的订单。 在那种情况下 - 由于继承如何工作,这是不可能的。