Re: [問題] 如何把父類別的資料複製到子類別?
※ 引述《apiod ( )》之銘言:
: public class A
: {
: public string FirstName { get; set; }
: public string LastName { get; set; }
: public string Address { get; set; }
: }
: public class B : A
: {
: public string company { get;set;}
/*新增這邊*/
public B(A x)
{
this.FirstName = x.FisrstName;
this.SecondName = x.SecondName;
this.Address = x.Address;
}
: }
: A a = new A();
: a.FirstName = "xx1";
: a.LastName = "xx2";
: a.Address = "xx3";
//方法1需要新增上面的部分
B b = new B(a);
//方法2
B b = new B();
b.FisrstName = a.FistName;
b.SecondName = a.SecondName;
b.Address = a.Address;
: 請問我該如何把A的資料複製給B呢?
: 感謝解惑
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.122.36.38
→
09/08 15:49, , 1F
09/08 15:49, 1F
→
09/08 15:49, , 2F
09/08 15:49, 2F
→
09/08 17:08, , 3F
09/08 17:08, 3F
→
09/08 19:18, , 4F
09/08 19:18, 4F
→
09/08 19:35, , 5F
09/08 19:35, 5F
→
09/08 20:53, , 6F
09/08 20:53, 6F
→
09/15 04:41, , 7F
09/15 04:41, 7F
→
09/18 00:06, , 8F
09/18 00:06, 8F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
C_Sharp 近期熱門文章
PTT數位生活區 即時熱門文章