Imports System
Imports System.Collections
Imports System.Collections.Generic
Imports System.Text
Namespace ArrayListSample
Class Person
Private Name As [String]
Private Age As Int32
Private Address As [String]
Public Sub New()
End Sub 'New
Public Sub New(ByVal Name As [String], ByVal Age As Int32, ByVal Address As [String])
Name = Name
Age = Age
Address = Address
End Sub 'New
Public Sub New(ByVal Name As [String], ByVal Age As Int32)
Name = Name
Age = Age
Address = [String].Empty
End Sub 'New
Public Sub New(ByVal Name As [String], ByVal Address As [String])
Name = Name
Age = 0
Address = Address
End Sub 'New
Public Sub New(ByVal Name As [String])
Name = Name
Age = 0
Address = [String].Empty
End Sub 'New
End Class 'Person
Class PeopleCollection
Inherits System.Collections.IEnumerable
Private arPeople As New ArrayList()
Public Sub New()
End Sub 'New
Public Sub AddPeople(ByVal p As Person)
arPeople.Add(p)
End Sub 'AddPeople
Public Sub ClearPeople()
arPeople.Clear()
End Sub 'ClearPeople
Private Count As Integer
Public ReadOnly Property PeopleCount() As Integer
Get
Return Count
End Get
End Property
Public Function GetEnumerator() As System.Collections.IEnumerator
Return arPeople.GetEnumerator()
End Function 'GetEnumerator
End Class 'PeopleCollection
Class Client
Public Shared Sub Main()
Dim myPeople As New PeopleCollection()
myPeople.AddPeople(New Person("Saurabh", 24, "Gurgaon"))
myPeople.AddPeople(New Person("Manu"))
Dim Person As Person
For Each Person In myPeople
Console.WriteLine(Person)
Next Person
Console.ReadLine()
End Sub 'Main
End Class 'Client
End Namespace 'ArrayListSample