return type of derived class
Is it possible to have a base-class method designate a return-value of "the" derived class, and then create and return an instance of (or "relative to") whichever derived class it's called from?
Code:
abstract class Base {
public static List<*DerivedClass*> BuildFromList(List<String> in_s) {
List<*DerivedClass*> rv = new List<*DerivedClass*>();
foreach (String s in in_s) {
rv.Add(new *DerivedClass*(s));
}
}
return rv;
}
Can this be done, or am I better off just using generics anyway?
Thanks.
Re: return type of derived class
The only way to do this is to use generics. Otherwise you can't define the type of the return value.
Darwen.
Re: return type of derived class