public PersonController() : this(new PersonBLL()) { }
2 回答
繁花如伊
TA贡献2012条经验 获得超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); //初始化带参构造函数14
//输出:初始化了带参构造函数15 Console.WriteLine("---------------------------------");16 PersonController pc1 = new PersonController();//初始化无参构造函数17 //输出:初始化了带参构造函数18 // 初始化了无参构造函数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("初始化了带参构造函数");30 }31 32 public PersonController()33 : this(new PersonBLL())34 {35 Console.WriteLine("初始化了无参构造函数");36 }37 }38 39 public class PersonBLL40 {41 }42 }在调用无惨构造函数的时候,会先初始化带参构造函数,再明白了吧
眼眸繁星
TA贡献1873条经验 获得超9个赞
PersonController类里面有一个构造函数 public PersonController(PersonBLL p)
直接调用该构造函数初始化了public PersonController()
- 2 回答
- 0 关注
- 471 浏览
添加回答
举报
0/150
提交
取消
