Which generic constraint requires a type argument in C# to have a public parameterless constructor?
Correct answer C. where T : new()
Explanation
The new() constraint lets generic code create instances with new T(). It must appear last when combined with other constraints, as in where T : Shape, new(). where T : class requires a reference type and where T : struct a non-nullable value type, but neither guarantees a parameterless constructor you can call. There is no where T : default constraint for this purpose.
Answer checked How we write and check questions
Discussion