ArrayList Item property in asp.net c#

ArrayList Item Property
.Net framework ArrayList Item property allow us to get or set the element at the specified index. the arraylist Item property exists under System.Collections namespace. this property require to pass a parameter named 'index'.

the 'index' parameter value type is System.Int32. this integer value represents the zero-based index of the element to get or set. this Item property return value type is System.Object which represents the element at the specified index. this arraylist Item property implements as IList.Item.

arraylist Item property throw ArgumentOutOfRangeException exception, if the 'index' is less than zero or 'index' is equals to or greater than Count. arraylist accepts null as a valid value and arraylist also allow duplicate elements.

the following asp.net c# example code demonstrate us how can we get or set (change) arraylist element at the specified index programmatically at run time in an asp.net application.
ArrayListItemProperty.aspx

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

<!DOCTYPE html>
<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        ArrayList colors = new ArrayList() { "Olive", "Indigo", "Violet", "Green", "Yellow" };

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

        Label1.Text += "<br /><br />ArrayList Index 0 Element: " + colors[0];
        Label1.Text += "<br />ArrayList Index 2 Element: " + colors[2];
        Label1.Text += "<br />ArrayList Index 4 Element: " + colors[4];

        colors[2] = "Red";

        Label1.Text += "<br /><br /><font color=Crimson>After Modify ArrayList Index 2 Element... ";
        foreach (string color in colors)
        {
            Label1.Text += "<br />" + color;
        }
        Label1.Text += "</font>";
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>ArrayList Item Property - How to get or set the element at the specified index</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:MidnightBlue; font-style:italic;">
            System.Collections.ArrayList Item Property
            <br /> How to get or set the element at the specified index
        </h2>
        <hr width="525" align="left" color="Navy" />
        <br />
        <asp:Label
             ID="Label1"
             runat="server"
             ForeColor="DarkOliveGreen"
             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 Item Property"
            Height="45"
            Font-Bold="true"
            ForeColor="DodgerBlue"
            />
    </div>
    </form>
</body>
</html>
More asp.net examples