C# ArrayList LastIndexOf(Object, Int32, Int32)
Description
ArrayList LastIndexOf(Object, Int32, Int32)
searches
for the specified Object and returns the zero-based index of the last occurrence
within the range of elements in the ArrayList that contains the specified
number of elements and ends at the specified index.
Syntax
ArrayList.LastIndexOf(Object, Int32, Int32)
has the following syntax.
public virtual int LastIndexOf(
Object value,//from w ww. j av a 2 s.c om
int startIndex,
int count
)
Parameters
ArrayList.LastIndexOf(Object, Int32, Int32)
has the following parameters.
value
- The Object to locate in the ArrayList. The value can be null.startIndex
- The zero-based starting index of the backward search.count
- The number of elements in the section to search.
Returns
ArrayList.LastIndexOf(Object, Int32, Int32)
method returns The zero-based index of the last occurrence of value within the range of elements
in the ArrayList that contains count number of elements and ends at startIndex,
if found; otherwise, -1.
Example
The following code example shows how to determine the index of the last occurrence of a specified element.
using System;// www . j a v a 2 s . c o m
using System.Collections;
public class SamplesArrayList {
public static void Main() {
ArrayList myAL = new ArrayList();
myAL.Add( "A" );
myAL.Add( "B" );
myAL.Add( "C" );
myAL.Add( "D" );
myAL.Add( "E" );
myAL.Add( "F" );
myAL.Add( "G" );
myAL.Add( "H" );
myAL.Add( "I" );
myAL.Add( "J" );
myAL.Add( "K" );
myAL.Add( "L" );
String myString = "G";
int myIndex = myAL.LastIndexOf( myString );
Console.WriteLine(myIndex );
myIndex = myAL.LastIndexOf( myString, 8 );
Console.WriteLine(myIndex );
myIndex = myAL.LastIndexOf( myString, 10, 6 );
Console.WriteLine( myIndex );
}
}
The code above generates the following result.