ArrayList LastIndexOf() method in asp.net c#

ArrayList LastIndexOf(Object) Method
.Net framework ArrayList.LastIndexOf(Object) method allow us to search the specified Object and return the zero-based index of the last occurrence within the entire ArrayList. the arraylist LastIndexOf() method exists in System.Collections namespace.

this method require to pass a parameter named 'value'. the 'value' parameter value type is System.Object which represents the Object to locate in the arraylist. this value can be null.

the LastIndexOf() method return value data type is System.Int32. this return integer value is the zero-based index of the last occurrence of the 'value' within the entire arraylist if the object found in arraylist; otherwise the method return -1. if the arraylist contains same object multiple times then the method return last occurrence index of the specified object.

the following asp.net c# example code demonstrate us how can we get the last occurrence index of a specified object within an arraylist programmatically at run time in an asp.net application.
ArrayListLastIndexOfMethod.aspx

<%@ Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html>

<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        ArrayList colors = new ArrayList() {"BlanchedAlmond","Brown","Cornsilk","Brown","CadetBlue"};

        Label1.Text = "ArrayList Elements....";
        Label1.Text += "<font color=DarkGreen>";
        foreach (string color in colors)
        {
            Label1.Text += "<br />" + color;
        }
        Label1.Text += "</font>";

        Label1.Text += "<br /><br />LastIndexOf(object) Method";
        Label1.Text += "<font color=Red>";
        Label1.Text += "<br />Last Index Of 'Brown': " +colors.LastIndexOf("Brown").ToString();
        Label1.Text += "</font>";
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>ArrayList LastIndexOf() - How to search specified Object and get index of last occurrence</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:MidnightBlue; font-style:italic;">
            System.Collections.ArrayList LastIndexOf() Method
            <br /> How to search specified Object and get index of last occurrence
        </h2>
        <hr width="625" align="left" color="Navy" />
        <br />
        <asp:Label
             ID="Label1"
             runat="server"
             ForeColor="Orchid"
             Font-Size="Large"
             Font-Names="Courier New"
             Font-Italic="true"
             Font-Bold="true"
             >
        </asp:Label>
        <br /><br />
        <asp:Button 
            ID="Button1"
            runat="server"
            OnClick="Button1_Click"
            Text="Test ArrayList LastIndexOf() Method"
            Height="45"
            Font-Bold="true"
            ForeColor="DodgerBlue"
            />
    </div>
    </form>
</body>
</html>
More asp.net examples