Let’s say I have
public class ClassA : Ione, Itwo
public class ClassB : Ione, Itwo
public class ClassC : Ione, Itwo
and a method MethodA that returns an instance of ClassA, ClassB or ClassC.
MethodA return type can be Ione or Itwo.
How can I achive that?.
I have tryed using generics like this:
public T MethodA<T>(myEnum e) where T : Ione, Itwo
but when typing return (T)new ClassA(); I get the error “Cannot convert type ClassA to T”.
Thanks.
Unite the two interfaces:
And use that as the return type.
You’ll probably need your classes to implement ITogether instead of Ione and Itwo, but you should try both ways.