The following code is a simple example of a program I am writing.
public class Y
{ }
public class X : Y
{ }
public class W : Y
{ }
public interface IAaa<T>
where T : Y
{
void Execute(T ppp);
}
public abstract class Aaa<T> : IAaa<T>
where T : Y
{
public abstract void Execute(T ppp);
}
public class Bbb : Aaa<X>
{
public override void Execute(X ppp)
{ }
}
public class Ccc : Aaa<W>
{
public override void Execute(W ppp)
{ }
}
public class Factory
{
public static IAaa<Y> Get(bool b)
{
if(b)
return new Bbb();
else
return new Ccc();
}
}
class Program
{
static void Main(string[] args)
{
IAaa<Y> aa;
aa = Factory.Get(true);
}
}
when I compile it I get the following errors
error CS0266: Cannot implicitly convert type 'ConsoleApplication3.Bbb' to 'ConsoleApplication3.IAaa'. An explicit conversion exists (are you missing a cast?)
error CS0266: Cannot implicitly convert type 'ConsoleApplication3.Ccc' to 'ConsoleApplication3.IAaa'. An explicit conversion exists (are you missing a cast?)
Is there any way to make it work?
;)- Soner GönülGetmethod will require a type parameter in both its definition and its call fromMain()- Alex