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

Solution Approaches

So how do you ensure that the list contains only items of a specific type? You do it by making the DynamicList class type-safe. In other words, by not permitting list to accept variables of the Object type, but only strongly typed values (doubles, integers, dates, and so on). The advantage of a strongly typed list is that assignments of the wrong type are caught at design time, rather than runtime.

Let’s revisit the source code of the DynamicList class and perform the appropriate changes. Create a new class and call it DynamicListDouble (you can find it in the sample project in its own class file). The following code example marks those sections in bold where the data type Object has been changed to Double:

Class DynamicListDouble ...

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