new constraint in generics

A

Alex Shirshov

Hi all!

How can i specify, that the generic class have the constructor?
With c# it's a new constraint.

For instance, i write
Code:
Class cls1(Of T)
Public Sub some()
Dim tt As New T() ' here is an error: 'New' cannot be used on a
type parameter not declared 'As New()'.
End Sub
End Class

Ok. Next try
Code:
Class cls1(Of T as New()) ' another error: Keyword does not name a type.
Public Sub some()
Dim tt As New T() 'previos error still here
End Sub
End Class
Now i have two error message!

Can anyone help?

P.S. My versions is VS.NET Whidbey 8.0.30703.4. and the .NET Framework
1.2.30703
 
M

Mattias Sjögren

Alex,
How can i specify, that the generic class have the constructor?

This didn't work in the PDC alpha release, but I believe it will in a
future beta release.



Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top