public PersonController() : this(new PersonBLL()) { }
2 回答

繁花如伊
TA貢獻(xiàn)2012條經(jīng)驗(yàn) 獲得超12個贊
using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 6 namespace ConsoleApplication1 7 { 8 class Program 9 { 10 static void Main(string[] args)11 {12 PersonBLL p = new PersonBLL(); 13 PersonController pc = new PersonController(p); //初始化帶參構(gòu)造函數(shù)14 //輸出:初始化了帶參構(gòu)造函數(shù)15 Console.WriteLine("---------------------------------");16 PersonController pc1 = new PersonController();//初始化無參構(gòu)造函數(shù)17 //輸出:初始化了帶參構(gòu)造函數(shù)18 // 初始化了無參構(gòu)造函數(shù)19 }20 }21 22 public class PersonController23 {24 private PersonBLL personBLL;25 26 public PersonController(PersonBLL p)27 {28 this.personBLL = p;29 Console.WriteLine("初始化了帶參構(gòu)造函數(shù)");30 }31 32 public PersonController()33 : this(new PersonBLL())34 {35 Console.WriteLine("初始化了無參構(gòu)造函數(shù)");36 }37 }38 39 public class PersonBLL40 {41 }42 }
在調(diào)用無慘構(gòu)造函數(shù)的時候,會先初始化帶參構(gòu)造函數(shù),再明白了吧

眼眸繁星
TA貢獻(xiàn)1873條經(jīng)驗(yàn) 獲得超9個贊
PersonController類里面有一個構(gòu)造函數(shù) public PersonController(PersonBLL p)
直接調(diào)用該構(gòu)造函數(shù)初始化了public PersonController()
- 2 回答
- 0 關(guān)注
- 432 瀏覽
添加回答
舉報(bào)
0/150
提交
取消