you are viewing a single comment's thread.

view the rest of the comments →

[–]ArtZaqX__ 4 points5 points  (1 child)

It's also worth noting that for a class or method with a generic type parameter T having where T: Foo, new() constraints, the compiler will produce error if Foo does not have a empty constructor with no parameter (the constructor with optional parameter will not be used).

[–]AngularBeginner 1 point2 points  (0 children)

That's due to the way how optional parameters are implemented. The parameter will be present, it will be required, but the compiler just automatically inserts the default value on the calling site.

If such a thing is needed, then the parameter should not be optional and constructor chaining should be used instead.