开发者

Beginner question about generics

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜