O'Reilly logo

Microsoft® Visual Basic® 2010 Developer’s Handbook by Klaus Löffelmann and Sarika Calla Purohit

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Generic Collections

Compared to “regular” collections, generic collections offer a significant advantage: they are always type-safe. Because they are not based on Object like the “normal” collections, such as the ArrayList class, they don’t accept any data type for elements; instead, they limit the collection items to whatever data type you specified when defining the collection.

For example, suppose that you define a Collection based on Integer with this code:

Dim locGenColl As New Collection(Of Integer)

Now you no longer run the risk of accidentally adding an element to your collection that is not an Integer. In other words, the following line would be marked as an error in the Editor at design time:

locGenColl.Add("An element")

Using generic collections ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required