'C# initialize a generic class of interface type with implementing class type [duplicate]
I want to know whether the below is achievable my any means.
If an interface object can be initialized with the implement class ie I1 objI1 = new C1() why can't a generic of the interface be initialized with the generic of the implementing class.
public interface I1
{
}
public class C1: I1
{
}
public class C2<T>
{
}
internal class Program
{
static void Main(string[] args)
{
C2<I1> obj = new C2<C1>(); //Cannot implicitly convert type C2<C1> to C2<I1>
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
