Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / December 2004

Tip: Looking for answers? Try searching our database.

Generics in VB.Net?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Robby - 13 Dec 2004 11:03 GMT
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
Ken Tucker [MVP] - 13 Dec 2004 11:14 GMT
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
Robby - 13 Dec 2004 11:37 GMT
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.

> Hi,
>
[quoted text clipped - 19 lines]
>
> Robby
Robby - 13 Dec 2004 11:54 GMT
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

> Thanks Ken.  I also found this article about generic collections.
>
[quoted text clipped - 57 lines]
>>
>> Robby
Tom Porterfield - 13 Dec 2004 11:43 GMT
> 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
[quoted text clipped - 4 lines]
> 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.
Signature

Tom Porterfield

Robby - 13 Dec 2004 11:51 GMT
Thanks Tom.  This answers my new question to Ken about non-collection
generic classes.

Robby

>> In C++ I can write template classes and in C# they have generic classes
>> that
[quoted text clipped - 12 lines]
> http://msdn2.microsoft.com/library/w256ka79.aspx for additional info, and
> also http://msdn2.microsoft.com/library/4a1b71ta.aspx.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.