Skip to content

Latest commit

 

History

History
34 lines (28 loc) · 2.36 KB

File metadata and controls

34 lines (28 loc) · 2.36 KB
title How to: Create a Collection Used by a Collection Initializer (Visual Basic)
ms.custom
ms.date 07/20/2015
ms.prod .net
ms.reviewer
ms.suite
ms.technology
devlang-visual-basic
ms.topic article
helpviewer_keywords
collection initializers [Visual Basic]
ms.assetid c858db10-424d-47e0-92cd-e08087cc5ebc
caps.latest.revision 8
author dotnet-bot
ms.author dotnetcontent

How to: Create a Collection Used by a Collection Initializer (Visual Basic)

When you use a collection initializer to create a collection, the Visual Basic compiler searches for an Add method of the collection type for which the parameters for the Add method match the types of the values in the collection initializer. This Add method is used to populate the collection with the values from the collection initializer.

Example

The following example shows an OrderCollection collection that contains a public Add method that a collection initializer can use to add objects of type Order. The Add method enables you to use the shortened collection initializer syntax.

[!code-vbVbVbalrCollectionInitializersHowTo2#4]

[!code-vbVbVbalrCollectionInitializersHowTo2#1]

[!code-vbVbVbalrCollectionInitializersHowTo2#2]

[!code-vbVbVbalrCollectionInitializersHowTo2#3]

See Also

Collection Initializers
How to: Create an Add Extension Method Used by a Collection Initializer