> >IMyInterFace i = GetClassType(); > >List<i> mylist = new List<i>(); > > >IMyInterFace GetClassType() >{ > if(SomeCondition) > return ClassA; > else > return classB; >} >Think you have to cast to the interface, Pete
static class Test_GenericInterface { internal static void Go() { List<ITest> theList = new List<ITest>(); theList.Add(GetElement(true)); } static ITest GetElement( bool isFirst) { if (isFirst) return (ITest)(new ClassA()); else return (ITest)(new ClassB()); } } interface ITest { int Get(); } class ClassA : ITest { public int Get() { return 1; } } class ClassB : ITest { public int Get() { return 3; } } }