Very closely related to the concept of object initialization syntax is collection initialization. This syntax makes it possible to populate a generic container (such as List<T>) or non-generic types (such as ArrayList) with items using a syntax that models that of a simple array.

Consider the following usage. As you examine the code, ponder the amount of code required under C# 2.0.

Unfortunately, the current release of VB does not support using collection initialization syntax. Therefore, VB programmers will need to create the container and then call the Add() method for each type they wish to insert.

' VBSub Main()' Make the container first.Dim myListOfRectangles As New List(Of Rectangle)

Copyright (c) 2008. Intertech, Inc. All Rights Reserved. This information is to be used exclusively as an online learning aid. Any attempts to copy, reproduce, or use for training is strictly prohibited.