Generics in VB.Net?

  • Thread starter Thread starter Robby
  • Start date Start date
R

Robby

In C++ I can write template classes and in C# they have generic classes that
are something like C++ template classes. Is there currently a why to write
them in VB? MS is adding C++ type functionality like operator overloading
to VB in version 2.0 of the .Net Framework. Will there be a way in version
2.0 to write generic classes in VB?

If not does anyone know the syntax to create an instance of a C# generic
class in VB?

Thanks

Robby
 
Hi,

In vb.net 2005 they will be supported.
http://msdn2.microsoft.com/library/x6z0kw1a.aspx

Ken
------------------

In C++ I can write template classes and in C# they have generic classes that
are something like C++ template classes. Is there currently a why to write
them in VB? MS is adding C++ type functionality like operator overloading
to VB in version 2.0 of the .Net Framework. Will there be a way in version
2.0 to write generic classes in VB?

If not does anyone know the syntax to create an instance of a C# generic
class in VB?

Thanks

Robby
 
Thanks Ken. I also found this article about generic collections.

http://msdn.microsoft.com/msdnmag/issues/04/09/AdvancedBasics/default.aspx

In this article they say that you will be able to use generics on methods
with the following syntax;

Public Sub Swap(Of MyType) (ByRef item1 As MyType, _
ByRef item2 As MyType)
Dim temp As MyType
temp = item1
item1 = item2
item2 = temp
End Sub

Do you know if this will be able to be done on class definitions so that
generic classes that are not collections can be created. For example, will
the following be valid in VB.Net 2005?

Public Class MyGenericClass(Of MyType)

Private data1 As MyType

Public Sub New(Of MyType) (newData as MyType)
data1 = newData
End Sub

Public Sub DoStuff(Of MyType) (data As MyType, repeat As Long)
'Do stuff
End Sub

End Class

Thanks again.

Robby.
 
In C++ I can write template classes and in C# they have generic classes that
are something like C++ template classes. Is there currently a why to write
them in VB? MS is adding C++ type functionality like operator overloading
to VB in version 2.0 of the .Net Framework. Will there be a way in version
2.0 to write generic classes in VB?

If not does anyone know the syntax to create an instance of a C# generic
class in VB?

They will be there in 2005. See
http://msdn2.microsoft.com/library/w256ka79.aspx for additional info, and
also http://msdn2.microsoft.com/library/4a1b71ta.aspx.
 
Thanks Tom. This answers my new question to Ken about non-collection
generic classes.

Robby
 
Hi Ken

Tom gave me a link that answers this new question about non-collection
generic classes. It seems I will not have to repeat the "(Of MyType)" in
the class method definitions.

Thanks again.

Robby
 
Back
Top