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" <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)
> 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