How to use generic abstract class as return type ?

Hi there!

I have something like this:

abstract class BaseClass
protected BaseClass(){}

class Class1 : BaseClass
public static Class1 Instance = new Class1();
private Class1(){}

class Class2 : BaseClass
public static Class2 Instance = new Class2();
private Class2(){}

public BaseClass Method(int z) where T: BaseClass
case 1:
return Class1.Instance;
case 2:
return Class2.Instance;

That is very important that those classes cannot be instantiated since their construstors are private so we cannot do like

[code]public BaseClass Method(int z) where T: BaseClass, **new()**[/code]

The problem arises that I cannot in switch clause return those Class1.Instance because it says "cannot convert Class1 to return type BaseClass" How can I use abstract class as return type ?? I just can not work this out. Would appreciate for any assisstance here.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion