先附上code
class TestA
{
public int ID { get; set; }
public string Name { get; set; }
public int Age { get; set; }
}
class TestB : TestA
{
public string CName { get; set; }
}
class Program
{
static void Main(string[] args)
{
TestA ta = getTestA();
TestB tb = getTestA() as TestB;
var temp = tb;
}
private static TestA getTestA()
{
return new TestA()
{
ID = 1,
Name = "AA",
Age = 18
};
}
}
目的是让TestB继承的属性直接给值而不用在B那边一个一个写入
爬了一天文没找到相关的资讯及解法
求有没有相类似的关键字让小弟可以去查