As per MSDN, the new() constraint is used to ensure that the type argument must have a public parameterless constructor. However, consider the example given below (taken from the same page).
public class Employee
{
public Employee(string name, int id)
{
Name = name;
ID = id;
}
public string Name { get; set; }
public int ID { get; set; }
}
class EmployeeList<T> where T : Employee, new()
{
}
Here, the Employee type does not have a parameterless/default constructor, yet this code compiles successfully. Can someone please elaborate on the usage of this constraint and why this works?