首页 > 其他 > 详细

构造方法调用另一个构造方法,用this

时间:2019-03-01 21:37:53      阅读:187      评论:0      收藏:0      [点我收藏+]
 1 using System;
 2 class Person
 3 {
 4     public int age;
 5     public string name;
 6     public Person(int age, string name){
 7         this.age = age;
 8         this.name = name;
 9     }
10     /*构造方法调用另一个构造方法,使用this*/
11     public Person():this(0,""){}
12 }
13 public class Test
14 {
15     public static void Main( string [] args )
16     {
17        Person p = new Person();
18        Console.WriteLine(p.age);
19        Person p1 = new Person(22,"Li Li");
20        Console.WriteLine(p1.name);
21     }
22 }

 

构造方法调用另一个构造方法,用this

原文:https://www.cnblogs.com/GoldenEllipsis/p/10458867.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!