For Answers, see/post comments

Create a Generic Colletion to store objects in VB.Net

The code will represent a user defined collections for storing objects and retriving objects from the Collection and to manipulate it.For example you can have the collection of class objects in this collection.This collection can be iterated using For Each.

Public Class GenericCollection
Implements IEnumerable, IEnumerator
Dim arr As New ArrayList

Public Function GetEnumerator()
As System.Collections.IEnumerator
Implements System.Collections.IEnumerable.GetEnumerator
Return arr.GetEnumerator()
End Function


Public ReadOnly Property Current() As Object
Implements System.Collections.IEnumerator.Current
Get
Return arr.GetEnumerator.Current()
End Get
End Property

Public Function MoveNext() As Boolean
Implements System.Collections.IEnumerator.MoveNext
GetEnumerator.MoveNext()
End Function

Public Sub Reset() Implements System.Collections.IEnumerator.Reset
arr.Clear()
End Sub

Public Sub Add(ByVal obj As object)
arr.Add(obj)
End Sub

Public Function Count() As Integer
Return arr.Count
End Function

Public Function RemoveAt(ByVal Index As Integer)
arr.RemoveAt(index)
End Function

Public Function Remove(ByVal obj As object)
arr.Remove(obj)
End Function

Public Function Item(ByVal Index As Integer) As object
Return arr.Item(Index)
End Function
End Class

No comments: