":this()"が参照するものを説明してください。私は代わりに "base"を使用します。 "this"にカーソルを移動すると、別のコンストラクターが表示されます。 また、 "base"で置き換えると、 "objectには1つの引数を取るコンストラクタが含まれていません"というエラーが返されます。"this"はコンストラクタごとに何を参照していますか?
class Employee { private string name; private string surname; private DateTime birthday; private double height; private double salary; public string Name { get { return name; } set { if (name != value) { name = value; } } } public string Surname { get { return surname; } set { if (surname != value) { surname = value; } } } public DateTime Birthday { get { return birthday; } set { if (birthday != value) { birthday = value; } } } public double Height { get { return height; } set { if (height != value) { height = value; } } } public double Salary { get { return salary; } set { if (salary != value) { salary = value; } } } public string Full { get { return name + " " + surname; } } public Employee() { name = "Mina"; surname = "Babayeva"; birthday = DateTime.Now.AddYears(-19); height=175; salary = 3500; } public Employee(string name, string surname, DateTime birthday, double height, double salary) : this(name, surname) { this.birthday = birthday; this.height = height; this.salary = salary; } public Employee(string name) : this() { this.name = name; } public Employee(string name, string surname) : this(name) { this.surname = surname; } public void Print() { Console.WriteLine("Name is {0}\nSurname is {1}\nHeight is {2}\nBirthday is {3}\nSalary is {4}", this.Name, this.Surname, this.Height, this.Birthday.ToString("dd/MM/yyyy"), this.Salary); } //////////////////////////////// Employee a = new Employee(); Employee b = new Employee("Adil", "Babayev"); Employee c = new Employee("Zumrud","Babayeva",DateTime.Now.AddYears(-52),167,1000000); Employee e = new Employee("Hanna"); a.Print(); Console.WriteLine(); b.Print(); Console.WriteLine(); c.Print(); Console.WriteLine(); e.Print(); Console.WriteLine();
この場合、構文と書式を再度確認してください。 – Abion47