C# 2.0 question about generic type parameter constructor-constraint

  • Thread starter Thread starter Dmitry Martynov
  • Start date Start date
D

Dmitry Martynov

What if I have some special constructors and do not have a default
constructor. It seems to be very useful when I do not want to forget to
initialize some fields properly. As I have understood classes with no
default constructor can not be arguments of generic types. Why I can not
specify "new ( smth. )" as a constraint of a generic parameter? Or may be
the document http://www.msdn.microsoft.com/vcsharp/language misses this
case?
 
Default constructors are only required if you specify the "new" constraint -
ou don't need them for generics in general.

We didn't add more complex constraints for constructors because we didn't
think the added utility was worth the additional complexity

--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://blogs.gotdotnet.com/ericgu/

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top