Jack Jack -4 years ago 123
C# Question

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 of getting the below result?

public abstract class SubClass : BaseClass
{
override ObservableCollection<int> Numbers {get;set;}
}


So the subclass has an observablecollection or is there a design pattern I could implement?

Answer Source

Generics can help you achieve similar behavior:

public abstract class BaseClass<T> where T : ICollection<int>
{
    public T Numbers { get; set; }
}

public abstract class SubClass : BaseClass<ObservableCollection<int>>
{

}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download