If your ArrayList is ordered, and contains strings of numbers (as illustrated in your post,) then the below function should work:
Private Function OKToInsertSorted(ByVal theArrayList As ArrayList, _
ByVal stringToInsert As String) As Boolean
With theArrayList
If CInt(stringToInsert) < CInt(.Item(.Count - 1)) Then Return False
If .Count <= 1 Then
If stringToInsert = "1" Then Return True Else Return False
End If
If .Item(.Count - 1).ToString = .Item(.Count - 2).ToString Then
Return True
Else
Return False
End If
End With
End Function
If your ArrayList is NOT ordered, but still contains strings of numbers (assuming you started with number "1",) then the following function should work:
Private Function OKToInsertUNSorted(ByVal theArrayList As ArrayList, _
ByVal stringToInsert As String) As Boolean
If stringToInsert = "1" Then Return True
Dim stringToCheck As String = CStr(CInt(stringToInsert) - 1)
Dim qry = From stringItem In theArrayList _
Where stringItem.ToString = stringToCheck _
Group By stringItem Into _
stringCount = Count()
For Each result In qry
If result.stringCount >= 2 Then Return True
Next
Return False
End Function
I put quite a bit of validation code in the first function based on some assumptions about what you were looking for, so your mileage may vary.