Collections in VB.NET

In this article We will learn how to use Collections in VB.NET.
  • 2402

Collections

Visual Basic .NET Collections are data structures that holds data in different ways for flexible operations . The important data structures in the Colletions are ArrayList , HashTable , Stack and Queue etc. In the following chapters you can see how to manage these data structures in your visual basic.net programs.Special set of classes to hold dynamic set of objects.

All such classes are provided under System.Collections namespace.

Example:

ArrayList class Each collection class provides

  • void Add() method
  • Int Count Property

Module Module1

    Sub Main(ByVal args As String())

        Dim ar As New ArrayList()

        ar.Add(35)

        ar.Add(90)

        ar.Add(34)

        Dim sum As Integer = 0

        For i As Integer = 0 To ar.Count - 1

            sum = sum + CInt(ar(i))

        Next

        Console.WriteLine("sum is {0}", sum)

    End Sub


End Module

 

Output:

 

  collection.gif

Boxing and Unboxing:

  • Boxing means conversion from value type to reference type.
  • Unboxing means conversion from reference type to type value. It can be achieved using cast operator.
  • Used in Collections.

Categories

More Articles

© 2013 dotNetheaven. All rights reserved.