Generic Beginner Question

Are these two statuses equivalent?

Public Class Class2(Of X As Class1)
Public Class Class2(Of X As {Class1})

What does "new" mean?

Public Class Class2(Of X As {Class1, New})
+3
source share
2 answers

Your first two statements are equivalent. Curly braces are about how to use a few common restrictions in VB.NET. In your case, even if there are brackets, there is only one limitation.

The keyword Newis a constraint that ensures that the type Thas a constructor that takes no parameters. Thus, your second definition guarantees that it Tis or inherits from Class1and has a constructor without parameters.

+5
source

Source: https://habr.com/ru/post/1787970/


All Articles