'Visual Basic 2008/2010 Collecties - Inleiding Object Oriented Programming Namespace Alternative2 Class Sentence ' LinkedList Type Private m_StartWord As Word = New Word With {.Value = "sentinel"} Public ReadOnly Property Count() As Integer Get Dim element As Word = m_StartWord Do Until element.NextWord Is Nothing element = element.NextWord Count += 1 Loop End Get End Property Default Public ReadOnly Property Item(ByVal index As Integer) As String Get If index >= 0 AndAlso index < Count Then Dim elementIndex As Integer = -1 Dim element As Word = m_StartWord Do Until elementIndex = index OrElse element.NextWord Is Nothing elementIndex += 1 element = element.NextWord Loop If elementIndex = index Then Item = element.Value End If End Get End Property Public Sub Add(ByVal word As String) Dim lastWord As Word = m_StartWord Do Until lastWord.NextWord Is Nothing lastWord = lastWord.NextWord Loop lastWord.NextWord = New Word With {.Value = word} End Sub Public Function IndexOf(ByVal word As String) As Integer Dim elementIndex As Integer = -1 Dim element As Word = m_StartWord.NextWord Dim found As Boolean Do Until element Is Nothing OrElse found elementIndex += 1 found = (element.Value = word) element = element.NextWord Loop If found Then IndexOf = elementIndex Else IndexOf = -1 End If End Function Public Function Contains(ByVal word As String) As Boolean Contains = (IndexOf(word) <> -1) End Function End Class Class Word ' LinkedListNode Type Private m_Value As String Public Property Value() As String Get Value = m_Value End Get Set(ByVal value As String) m_Value = value End Set End Property Private m_NextWord As Word Public Property NextWord() As Word Get NextWord = m_NextWord End Get Set(ByVal value As Word) m_NextWord = value End Set End Property End Class End Namespace 'Bezoek www.vbvoorbeelden.be voor meer Visual Basic voorbeelden. 'Copyright - De Wolf / vbvoorbeelden - 2003-2010 - Alle rechten voorbehouden.