I tried to create same base generic variable and assign to it every generic object that have param wich inheritance same interface , but I got an error "Cannot implicitly convert type". Can some help me understand this ?
public interface ISomthink
{
}
public class Somethink: ISomthink
{
}
public class Somethink2: ISomthink
{
}
public class MyGeneric<T> where T:ISomthink
{
}
public class Program
{
public static void Main(string[] args)
{
ISomthink s1 = null;
s1=new Somethink();
s1 = new Somethink2();
MyGeneric<ISomthink> sg = null;
sg=new MyGeneric<Somethink>();//Error Cannot implicitly convert type
sg = new MyGeneric<Somethink2>();//Error Cannot implicitly convert type
}
}