使用方式之一:
this,在构造函数中使用。
当使用构造函数的重载时,可使用this关键字。
1
//
构造函数-重载
2
public Student(int id, string name, int age, int math)
3 {
4this.Id = id;
5this.Name = name;
6this.Age = age;
7this.Math = math;
8 }
910//this关键字,具有最少参数的构造器调用具有最多参数的构造器11public Student(int id, int math)
12 :this(id,"NULL",0, 100)
13 {
14 }
当调用 public Student(int id, int math)(命名为构造函数1)构造函数的时候,因为使用了this关键字,所以执行的顺序是,当执行构造函数1的时候,系统会直接把构造函数1中的参数,传递给 public Student(int id, string name, int age, int math)(命名为构造函数2),然后在构造函数2中,把值赋给属性。
原文:http://www.cnblogs.com/KTblog/p/4437643.html
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!