Bitte erläutern Sie, was ": this()" sich bezieht.Kann ich stattdessen "base" verwenden. Wenn ich den Cursor auf "this" bewege, wird ein anderer Konstruktor angezeigt. Oder, wenn ich es durch "Basis" ersetze, gibt es diesen Fehler: "Objekt enthält keinen Konstruktor, der 1 Argument nimmt".Worauf bezieht sich "das" für jeden Konstruktor?
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();
Sie können Ihre Syntax und Formatierung in diesem Fall überprüfen. – Abion47