vb.net - Extending a base class to a derived class -
we have 2 classes basicrace & advancedrace. advancedrace inherits basicrace
i have basicrace want 'convert' advanced class.
see code below example:
module module1 sub main() dim brace new basicrace {.courseid = 1, .meetingdate = "2013-05-01", .racenumber = 1} dim arace new advancedrace ' upgrade brace advancedrace??????? end sub end module public class basicrace public property meetingdate date public property courseid integer public property racenumber integer end class public class advancedrace inherits basicrace public property racetitle string end class any great - i'm starting think can not done unless write function convert basicrace advancedrace going through each property 1 one?
you can't "convert" base class subclass such (you can't change type of existing object), can create new instance of subclass copies properties base class.
typical ways of implementing classes might be:
- a constructor in
advancedracetakesbasicraceparameter , copies properties it - a static method in
advancedracetakesbasicraceparameter, creates new object copied properties, , returns it
it's worth noting result in 2 separate objects (one of each type) aren't linked @ - changes in advancedrace object won't reflected in basicrace or vice-versa.
Comments
Post a Comment