this关键字
当前类的对象
在类当中显示的调用本类的构造函数 :this
class GouZao
{
public GouZao(string name,int age,char sex,double chinese,double math,double english) //含参的构造函数
{
this.Name = name;
this.Age = age;
this.Sex = sex;
this.Chinese = chinese;
this.Math = math;
this.English = english;
}
public GouZao(string name,double chinese,double english):this(name,18,'男',chinese,20.3,english)
{
Console.WriteLine("this关键字调用本类的构造函数");
}
private string _name;
private int _Age;
private char _sex;
private double _Chinese;
private double _Math;
private double _English;
public string Name
{
get { return _name; }
set { _name = value; }
}
public int Age
{
get { return _Age; }
set { _Age = value; }
}
public char Sex
{
get { return _sex; }
set { _sex = value; }
}
public double Chinese
{
get { return _Chinese; }
set { _Chinese = value; }
}
public double Math
{
get { return _Math; }
set { _Math = value; }
}
public double English
{
get { return _English; }
set { _English = value; }
}
public string Say()
{
return "输出的姓名是:" + _name + "今年" + _Age + "岁,性别是" + _sex+"语文成绩"+_Chinese+"分,数学成绩"+_Math+"分,英语成绩"+_English+"分";
}
}
//在Main函数中调用
GouZao gz = new GouZao("张三",20.4,44.4);
Console.WriteLine(gz.Say());
在执行的过程中,从打印结果的顺序可以看出
当实例化创建完一个对象后调用构造函数的顺序,