C # override base class collection type
I have a base class with
public abstract class BaseClass
{
ICollection<int> Numbers {get;set;}
}
Is there a way to get the result below?
public abstract class SubClass : BaseClass
{
override ObservableCollection<int> Numbers {get;set;}
}
So, does the subclass have an observable collective, or is there a design pattern I could implement?
+3
source to share
3 answers
You cannot override it.
One solution might be to create a new property with a different name:
public abstract class SubClass : BaseClass
{
public ObservableCollection<int> ObservableNumbers => (ObservableCollection<int>)Numbers;
}
Or as follows: (if you really need to install it)
public abstract class SubClass : BaseClass
{
public ObservableCollection<int> ObservableNumbers
{
get { return (ObservableCollection<int>)Numbers; }
set { Numbers = value; }
}
}
And don't forget to make the property Numbers
public or internal!
0
source to share