Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
How to use generic abstract class as return type ?
I have something like this:
abstract class BaseClass
class Class1 : BaseClass
public static Class1 Instance = new Class1();
class Class2 : BaseClass
public static Class2 Instance = new Class2();
public BaseClass Method(int z) where T: BaseClass
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.
0 · ·