Are these two statments equivalent?
Public Class Class2(Of X As Class1)
Public Class Class2(Of X As {Class1})
What doe开发者_如何学Cs the "New" mean?
Public Class Class2(Of X As {Class1, New})
Your first two statements are equivalent. The curly brackets are how to use multiple generic constraints in VB.NET. In your case even though there are brackets, there is only a single constraint.
The New
keyword is a constraint that ensures the type T
has a constructor that takes no parameters. So your second definition ensures that T
is or inherits from Class1
and has parameterless constructor.
Read these links:
- Class Statement Syntax
- Type List Description
- New Keyword Explanantion
精彩评论