Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / General 2 / August 2006



Tip: Looking for answers? Try searching our database.

generics

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
xxx - 29 Aug 2006 04:56 GMT
could u provide me a example on generics in vb.net.... what are the
merits of using  generics....and its relation with the common language
runtime
Jan Hyde - 29 Aug 2006 08:55 GMT
"xxx" <arunpec121@yahoo.co.in>'s wild thoughts were released
on 28 Aug 2006 20:56:22 -0700 bearing the following fruit:

>could u provide me a example on generics in vb.net.... what are the
>merits of using  generics....and its relation with the common language
>runtime

dotnet groups have 'dotnet' in their name, this one if for
VB6 (and below)

Jan Hyde (VB MVP)

Signature

Koolah    :  Temperature change (Jan Hyde)

Tom Shelton - 30 Aug 2006 22:05 GMT
> could u provide me a example on generics in vb.net.... what are the
> merits of using  generics....and its relation with the common language
> runtime

xxx,

As stated, this is probably not as good a place as the .net newsgroups.
Those have already been pointed out to you, so I won't repost those -
but, I will give you a brief answer to your question:

Simple generics example:

Option Strict On
Option Explicit On

Imports System
Imports System.Collections.Generic

Module Module1

   Sub Main()
       Dim lst1 As New List(Of Integer)(New Integer() {1, 2, 3, 4, 5,
6})
       Dim lst2 As New List(Of String)(New String() {"a", "b", "c",
"d", "e"})

       Console.WriteLine("List 1")
       WriteList(lst1)

       Console.WriteLine("List 2")
       WriteList(lst2)

   End Sub

   Sub WriteList(Of T)(ByVal lst As List(Of T))
       For Each item As T In lst
           Console.WriteLine(item)
       Next
       Console.WriteLine()
   End Sub

End Module

As for the merits of generics...

Speed, since using genrics avoids boxing operations - which  was
especially prevalent when using value types with collections in 1.0 and
1.1 (ArrayList, HashTable, etc).

Type saftey - again since ArrayList and the other collection objects
accepted any object, it was possible to stick objects of mutiple types
in a list.  Sometimes that's what you want - but, most often it isn't.
The solution in 1.0 and 1.1 was to write a custom collection object to
store your objects.  Now, with generics you don't have to.

I could probably come up with others, but these are the two biggest off
the top of my head.  As for it's relation to the runtime - well,
generics are integral part of the 2.0 runtime.  That's why 2.0
assemblies can't be run on 1.0 and 1.1 runtimes - the metadata format
has changed, so they those runtimes can't load 2.0 assemblies.

--
Tom Shelton
 
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



©2009 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.