一、代表当前类的实例对象
二、调用当前类的构造函数
三、base用法
namespace ConsoleApplication1
{
class this用法
{
person p1 = new person("张三", 20);
}
class person
{
public string Name
{
get; set;
}
public int Age
{
get; set;
}
public double Height
{
get; set;
}
public person(string name, int age, double height)
{
//此处的this代表当前类的实例对象
this.Age = age;
this.Name = name;
this.Height = height;
}
//此处的this调用person类的三个参数的构造函数,将两个参数的构造函数name和height参数传给三个参数的构造函数
public person(string name, double height) : this(name, 0, height)
{
//this.Name = name;
//this.Height = height;
}
}
class Student:person
{
//不加上base默认继承父类的无参构造函数,base指定继承父类某个构造函数
public Student(string name, double height, string id):base(name, height)
{
this.Id = id;
}
public string Id
{
get; set;
}
public double Value
{
get; set;
}
}
}