The Employee constructor takes three arguments, but you're not passing any: new Employee()
.
You could simply change your initializers to passed constructor arguments:
var angajat = new Employee("ion", "28", 0770335978);
If you like having the properties named, you can use parameter names:
var angajat = new Employee(
name: "ion",
dateOfBirth: "28",
phoneNumber: 0770335978);
Or you could give your Employee
class a constructor that takes no arguments, and rely on users to initialize properties they want to initialize.
public Employee()
{
}
This latter would be more dangerous in some ways because people could easily forget to initialize the values.
You may also want to consider using C# 9's new record
feature.
public record Employee(string Name, string DateOfBirth, int PhoneNumber);
var angajat = new Employee(
Name: "ion",
DateOfBirth: "28",
PhoneNumber: 0770335978);
The ToString() method, in either case, can look like this:
public override string ToString() => $"{Name} | {DateOfBirth} | {PhoneNumber}";
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…