Compartilhar via


Como gerenciar grupos de objetos no Visual Basic

For many applications, you want to be able to create and manage groups of related objects. Há duas maneiras de agrupar objetos: Criando conjuntos de objetos e Criando coleções de objetos.

Arrays of Objects

Arrays are relatively inflexible structures. If you want to change the size of the array at run time, you must use the instrução ReDim (Visual Basic) to redeclare it. All elements of the array must be of the same type. On the other hand, arrays allow you to process all your elements sequentially, and you can have empty elements of an array. For these reasons, arrays are most useful for creating and working with a fixed number of strongly-typed objects.

For more information, see Como: Criar uma matriz de objetos (Visual Basic).

Collections of Objects

Collections provide a more flexible way of working with groups of objects. A collection is a class, so you must declare a new collection before you can add elements to that collection. Unlike arrays, the group of objects you work with can grow and shrink dynamically as the needs of the application change. You can assign a key to any object that you put into a collection so that you can retrieve it and manipulate it based on that key.

Você pode criar uma coleção generalizada a partir de Collection classe. If you want a specific functionality in a collection, for example a dictionary or a linked list, you can create it from one of the classes in the System.Collections namespace of the .NET Framework. Even more specialized collection classes are available in the System.Collections.Specialized namespace.

If your collection is limited to elements of only one data type, you can use one of the classes in the System.Collections.Generic namespace. A generic collection enforces type safety so that no other data type can be added to it. When you retrieve an element from a generic collection, you do not have to determine its data type or convert it.

For more information, see Como: Criar uma coleção de objetos (Visual Basic).

Consulte também

Tarefas

Como: adicionar, excluir e recuperar itens de uma coleção (Visual Basic)

Referência

System.Collections

System.Collections.Generic

System.Collections.Specialized

Conceitos

Matrizes no Visual Basic

Coleções em Visual Basic

Coleção de Classes do Visual Basic

Outros recursos

Objetos e Classes no Visual Basic