Work with collections in VB.NET

This article helps you to understanding the working of Collection Class.
  • 2108

Collection is an object that can hold one or more object  like to it consists of all of the controls objects on the form. It do not have a fixed size, the size of a collection is adjusted whenever an item is added or deleted. You can store any type of object in a collection. One of the limitation of collection is that you can not update an items in a collection.

To explain the use of Collection class, First create a new collection object called Name List, and than add 4 name titles to the collection, now to access each item in a collection you have to use For each Loop.

The common properties and methods of the collection class is:

Property's: Count and Item(index)

Methods: Add(object) and Remove(index)

Example

     
Imports System.Windows.Forms
    Module Module1
        Sub Main()
            Dim NameList As New Collection
            NameList.Add(
"MANISH")
            NameList.Add(
"RAHUL
            Dim sMessage As String
            Dim
sNameList As String
            For
Each sNameList In NameList
                sMessage &= sNameList & ControlChars.CrLf
            Next
            MessageBox.Show(sMessage, "NameList Collection")
        End Sub
    End
Module

OUTPUT

10.gif
 

CONCLUSION

I hope this article helps you to understand the working or use of collection class which is the basic class for creating and using collections.

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.