C# ArrayList LastIndexOf(Object)

Description

ArrayList LastIndexOf(Object) searches for the specified Object and returns the zero-based index of the last occurrence within the entire ArrayList.

Syntax

ArrayList.LastIndexOf(Object) has the following syntax.


public virtual int LastIndexOf(
  Object value
)

Parameters

ArrayList.LastIndexOf(Object) has the following parameters.

  • value - The Object to locate in the ArrayList. The value can be null.

Returns

ArrayList.LastIndexOf(Object) method returns The zero-based index of the last occurrence of value within the entire the ArrayList, 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;/*from   w  w w.ja va  2 s. com*/
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.





















Home »
  C# Tutorial »
    System.Collections »




ArrayList
BitArray
Comparer
Hashtable
Queue
SortedList
Stack