473,387 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Generics in VB.Net?


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
Nov 21 '05 #1
5 1284
Hi,

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

Ken
------------------
"Robby" <ed****@not.my.email.com> wrote in message
news:e9**************@TK2MSFTNGP11.phx.gbl...

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

Nov 21 '05 #2

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

http://msdn.microsoft.com/msdnmag/is...s/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.

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:uU**************@tk2msftngp13.phx.gbl...
Hi,

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

Ken
------------------
"Robby" <ed****@not.my.email.com> wrote in message
news:e9**************@TK2MSFTNGP11.phx.gbl...

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

Nov 21 '05 #3
On Tue, 14 Dec 2004 00:03:39 +1300, Robby wrote:
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.
--
Tom Porterfield
Nov 21 '05 #4

Thanks Tom. This answers my new question to Ken about non-collection
generic classes.

Robby
"Tom Porterfield" <tp******@mvps.org> wrote in message
news:1u***************@tpportermvps.org...
On Tue, 14 Dec 2004 00:03:39 +1300, Robby wrote:
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.
--
Tom Porterfield

Nov 21 '05 #5
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
"Robby" <ed****@not.my.email.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...

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

http://msdn.microsoft.com/msdnmag/is...s/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.

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:uU**************@tk2msftngp13.phx.gbl...
Hi,

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

Ken
------------------
"Robby" <ed****@not.my.email.com> wrote in message
news:e9**************@TK2MSFTNGP11.phx.gbl...

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


Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
by: Bernardo Heynemann | last post by:
How can I use Generics? How can I use C# 2.0? I already have VS.NET 2003 Enterprise Edition and still can´t use generics... I´m trying to make a generic collection myCollection<vartype> and...
2
by: Mr.Tickle | last post by:
So whats the deal here regarding Generics in the 2004 release and templates currently in C++?
23
by: Luc Vaillant | last post by:
I need to initialise a typed parameter depending of its type in a generic class. I have tried to use the C++ template form as follow, but it doesn't work. It seems to be a limitation of generics...
12
by: Michael S | last post by:
Why do people spend so much time writing complex generic types? for fun? to learn? for use? I think of generics like I do about operator overloading. Great to have as a language-feature, as...
5
by: anders.forsgren | last post by:
This is a common problem with generics, but I hope someone has found the best way of solving it. I have these classes: "Fruit" which is a baseclass, and "Apple" which is derived. Further I have...
11
by: herpers | last post by:
Hello, I probably don't see the obvious, but maybe you can help me out of this mess. The following is my problem: I created two classes NormDistribution and DiscDistribution. Both classes...
9
by: sloan | last post by:
I'm not the sharpest knife in the drawer, but not a dummy either. I'm looking for a good book which goes over Generics in great detail. and to have as a reference book on my shelf. Personal...
1
by: Vladimir Shiryaev | last post by:
Hello! Exception handling in generics seems to be a bit inconsistent to me. Imagine, I have "MyOwnException" class derived from "ApplicationException". I also have two classes...
7
by: SpotNet | last post by:
Hello NewsGroup, Reading up on Generics in the .NET Framework 2.0 using C# 2005 (SP1), I have a question on the application of Generics. Knowingly, Generic classes are contained in the...
13
by: rkausch | last post by:
Hello everyone, I'm writing because I'm frustrated with the implementation of C#'s generics, and need a workaround. I come from a Java background, and am currently writing a portion of an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.