using System;
namespace this_Construct
{
class Person
{
string name;
int age;
string sex;
int ID;
public Person(string sex, int age, int ID)
{
this.age = age;
this.ID = ID;
this.sex = sex;
}
public Person(string name, string sex, int age, int ID) : this(sex, age, ID)
{
this.name = name;
}
// 用this关键字实现调用本类中的其他构造函数
public void print()
{
Console.WriteLine("name:{0}\t,age:{1}\t,id:{2}\t,sex:{3}\t", this.name, this.age, this.ID, this.sex);
}
}
class Program
{
static void Main(string[] args)
{
// Console.WriteLine("Hello World!");
Person person = new Person("xiaobai", "male", 18, 001);
person.print();
}
}
}
C#构造函数的 this
最新推荐文章于 2022-07-14 23:10:20 发布