c# - Creating a child object using a parent object -
let have these classes:
class {}; class b : {} ; and function return a:
public read_an_a(); since b child of a, i'd able read it's a properties in following sense:
b b = new b ( read_an_a() ); (that assuming use of default copy constructor)
or maybe this:
b b = (b) read_an_a (); all of above broken, right way achieve that?
one way of doing add constructor of b takes a, , harvests relevant parts it:
public b(a a) { this.x = a.x; this.y = a.y; } your b class in best position know take, approach reasonably clean, too. lets write
b b = new b(read_an_a()); like suggested in question. of course b need other constructors, too.
Comments
Post a Comment