|
-
October 25th, 2011, 09:01 AM
#1
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.
-
October 26th, 2011, 04:48 AM
#2
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.
-
October 26th, 2011, 08:50 AM
#3
Re: return type of derived class
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|