Use static Employee.Create factory instead of public constructor.
Ready — edit the code above and click Run.
using System;
class Employee {
public string Name { get; private set; }
private Employee(string name) => Name = name;
public static Employee Create(string name) => new Employee(name);
}
class Program {
static void Main() {
var e = Employee.Create("Sara");
Console.WriteLine(e.Name);
}
}
Try solving on your own first, then reveal the official answer.
Factory pattern controls object creation—common in enterprise C#.