猿问

解释一下代码

 public PersonController()
            : this(new PersonBLL()) { }


潇潇雨雨
浏览 410回答 2
2回答

繁花如伊

 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 }在调用无惨构造函数的时候,会先初始化带参构造函数,再明白了吧

眼眸繁星

PersonController类里面有一个构造函数 public PersonController(PersonBLL p)直接调用该构造函数初始化了public PersonController()
随时随地看视频慕课网APP
我要回答