I’m trying to create a class that accepts two generic types (IQueue, IItem) for example:
public class Coordinator<T,K>
where T : IQueue<K>
where K : IItem
{
private T<K> collection = new T<K>();
}
Where:
public interface IQueue<T> where T : IItem
{
}
public class MyQueue<T> : IQueue<T>
where T : IItem
{
}
But the compiler does not like:
private T<K> collection = new T<K>();
Is this at all possible?
Thanks!
I think you need to do the following:
Because you are saying: The coordinator gets an IQueue, but you are trying to construct a MyQueue with more specific information.
Using the already discussed
Activator, you can do this without compiler errors: