Search Object and returns index of the last occurrence within the ArrayList in CSharp
Description
The following code shows how to search Object and returns index of the last occurrence within the ArrayList.
Example
using System;// ww w . jav a2s .c om
using System.Collections;
public class SamplesArrayList {
public static void Main() {
ArrayList myAL = new ArrayList();
myAL.Add( "A" );
myAL.Add( "G" );
myAL.Add( "C" );
myAL.Add( "D" );
myAL.Add( "G" );
myAL.Add( "F" );
myAL.Add( "G" );
myAL.Add( "H" );
myAL.Add( "I" );
myAL.Add( "J" );
myAL.Add( "K" );
myAL.Add( "G" );
String myString = "G";
int myIndex = myAL.LastIndexOf( myString );
Console.WriteLine(myIndex );
}
}
The code above generates the following result.