Collection Examples

Collection Example


Imports System.Collections.Generic
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms

Namespace CollectionExample1
    Public Partial Class Form1
        Inherits Form

        Public Sub New()
            InitializeComponent()
        End Sub

        Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
            Dim i As Integer = 0
            Dim ItemList As ArrayList = New ArrayList()
            ItemList.Add("Apr")
            ItemList.Add("May")
            ItemList.Add("Feb")
            ItemList.Add("Jan")
            ItemList.Add("Mar")
            MessageBox.Show("Shows Added Items")

            For i = 0 To ItemList.Count - 1
                MessageBox.Show(ItemList(i).ToString())
            Next

            ItemList.Insert(3, "Jun")
            ItemList.Sort()
            MessageBox.Show("Shows Added Items After Sorting")

            For i = 0 To ItemList.Count - 1
                MessageBox.Show(ItemList(i).ToString())
            Next

            ItemList.Remove("Jan")
            ItemList.RemoveAt(3)
            MessageBox.Show("Shows final Items the ArrayList")

            For i = 0 To ItemList.Count - 1
                MessageBox.Show(ItemList(i).ToString())
            Next
        End Sub
    End Class
End Namespace

©Copyright 2016 All Rights Reserved LearnDotNetHome.com