Mega Code Archive

 
Categories / VB.Net / Data Structure
 

ArrayList IndexOf searches for the specified Object and returns the zero-based index

Imports System Imports System.Collections Imports Microsoft.VisualBasic Public Class SamplesArrayList     Public Shared Sub Main()         Dim myAL As New ArrayList()         myAL.Add("A")         myAL.Add("B")         myAL.Add("C")         myAL.Add("D")         myAL.Add("B")         myAL.Add("C")         myAL.Add("D")         myAL.Add("B")         myAL.Add("C")         myAL.Add("D")         myAL.Add("B")         myAL.Add("C")         myAL.Add("D")         myAL.Add("B")         myAL.Add("C")         myAL.Add("D")         PrintIndexAndValues(myAL)         Dim myString As [String] = "B"         Dim myIndex As Integer = myAL.IndexOf(myString)         Console.WriteLine(myIndex)         myIndex = myAL.IndexOf(myString, 4)         Console.WriteLine("The first occurrence of ""{0}"" between index 4 and the end is at index {1}.", myString, myIndex)     End Sub 'Main     Public Shared Sub PrintIndexAndValues(ByVal myList As IEnumerable)         Dim i As Integer         Dim obj As [Object]         For Each obj In myList             Console.WriteLine("   [{0}]:    {1}", i, obj)             i = i + 1         Next obj         Console.WriteLine()     End Sub End Class