How to use for each loop on a list of string?

qadeer37

Well-known member
Joined
May 1, 2010
Messages
63
Location
Hyderabad,pakistan
Programming Experience
1-3
Public Class CustomerList : Inherits System.Collections.CollectionBase

Public Sub Add(ByVal name As String)
Me.InnerList.Add(name)

End Sub
Public ReadOnly Property items(ByVal i As Integer) As String
Get
Return CType(InnerList.Item(i), String)

End Get
End Property
End Class

Public Class Form1
Dim CList As CustomerList

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
CList = New CustomerList
CList.Add("Qadeer")

'How to use For Each loop?

MessageBox.Show(CList.items)
Next


End Sub
End Class
:(
 
Don't use CollectionBase in .NET 3.5. If you want to create a custom collection then inherit the generic Collection class:
VB.NET:
Public Class CustomerList
    Inherits System.Collections.ObjectModel.Collection(Of String)
End Class
That's all you need unless you want custom behaviour. All standard collection functionality is inherited.

That said, what's the point of such a collection, given that you already have the StringCollection and List(Of String) classes?

As for using a For Each loop, you would use it the same way as you would any other For Each loop. Do you know how a For each loop works?
 
Back
Top