I was wondering how to do this, consider the following classes
public class Fruit { public string Name { get; set; } public Color Color { get; set; } } public class Apple : Fruit { public Apple() { } }
How can I create a new fruit, but introduced to Apple, there is a way to create a bunch of fruits and make them apples with a name and a set of flowers. Do I need to manually copy manually?
Of course it fails
Fruit a = new Fruit(); a.Name = "FirstApple"; a.Color = Color.Red; Apple wa = a as Apple; System.Diagnostics.Debug.Print("Apple name: " + wa.Name);
I need to pass Fruit to AppleCTor and manually set the name and color (or 1-n properties). Is there a better design for this?
source share