Have you been thinking about getting into generics with Visual Basic 2005 but have not found a simple place to start?
Before you try to create your own generic classes, methods, structures, or interfaces, walk first - by using some of the generic types built into the .NET 2.0 class library.
For example, try using the very useful and easy to use generic 'List' class.
Here's an example of using a 'List' to store integers:
' Declare a variable named myList of type List passing
' in a type argument of Integer.
Dim myList As New List(Of Integer)
' Add two integers to myList.
myList.Add(1)
myList.Add(2)
' Loop through the integers in myList.
For Each int As Integer In myList
' Display the integer as a string.
MessageBox.Show(int.ToString)
Next
Here's an example of using a 'List' to store strings:
' Declare a variable named myList of type List passing
' in a type argument of String.
Dim myList As New List(Of String)
' Add two strings to myList.
myList.Add("Dog")
myList.Add("Cat")
' Loop through the strings in myList.
For Each str As String In myList
' Display the string.
MessageBox.Show(str)
Next
Learn more about the generic 'List' class and generics in general in Visual Basic 2005 by clicking the links below:
List Generic Class
Using Generics in Visual Basic 2005
Defining and Using Generics in Visual Basic 2005