我想知道是否有人可以帮助我填充派生类的基本属性的最佳方式。我想使用一种方法来填充基地的属性,无论是使用基地还是儿童。填充基础属性的最佳方式是什么?
这里是什么,我问一个例子:
public class Parent
{
public string Id {get; set;}
}
public class Child : Parent
{
public string Name {get; set;}
}
public Parent GetParent(int ID)
{
Parent myParent = new Parent();
//Lookup and populate
return Parent;
}
public Child GetChild(string name)
{
Child myChild = new Child();
//Use the GetParent method to populate base items
//and then
//Lookup and populate Child properties
return myChild;
}
通过构造函数填充? – sll 2013-02-21 15:54:20
可能重复[填充基类与子类?](http://stackoverflow.com/questions/3649354/populate-base-class-along-with-child-class) – MethodMan 2013-02-21 15:55:22
你可以做什么'sll'有建议或者你可以采取继承路线.. – MethodMan 2013-02-21 15:55:59