Search an Object and returns the zero-based index of the first occurrence within the entire ArrayList in CSharp

Description

The following code shows how to search an Object and returns the zero-based index of the first occurrence within the entire ArrayList.

Example


using System;//from  ww w . j  av a2 s.  co m
using System.Collections;
public class SamplesArrayList
{

    public static void Main()  
    {
        ArrayList myAL = new ArrayList();
        myAL.Add( "the" );
        myAL.Add( "quick" );
        myAL.Add( "brown" );
        myAL.Add( "fox" );
        myAL.Add( "jumps" );
        myAL.Add( "over" );
        myAL.Add( "the" );
        
        foreach (Object obj in myAL){
            Console.WriteLine(obj);
        }
        String myString = "the";
        int myIndex = myAL.IndexOf( myString );
        Console.WriteLine( myIndex );

    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Collections »




ArrayList
BitArray
Collection
Comparer
HashSet
Hashtable
LinkedList
List
ListDictionary
OrderedDictionary
Queue
SortedList
SortedSet
Stack
StringCollection
StringDictionary