ArrayList Contains() method in asp.net c#

ArrayList.Contains() Method
.Net framework ArrayList Contains() method allow us to determine whether an element is in the ArrayList. this arraylist Contains() method exists under System.Collections namespace. this Contains() method has a required parameter named 'item'.

the 'item' property value type is System.Object, which represents the Object to locate in the ArrayList. the value can be null. Contains() method return value data type is System.Boolean. this method return 'true', if the 'item' is found in the arraylist; otherwise method return 'false'.

the Contains() method implements as IList.Contains(Object) and this method perform a linear search. Contains() method determines equality by calling Object.Equals.

the following asp.net c# example code demonstrate us how can we determine whether an element exists in arraylist programmatically at run time in an asp.net application.
ArrayListContainsMethod.aspx

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

<!DOCTYPE html>

<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        ArrayList colors = new ArrayList() {"Bisque","Aqua","DarkOrange","Salmon"};

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

        Label1.Text += "<br /><br />'Salmon' element exists in ArrayList? " + colors.Contains("Salmon");
        Label1.Text += "<br /><br />'Green' element exists in ArrayList? " + colors.Contains("Green");
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>How to determine whether an element exists in ArrayList</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:MidnightBlue; font-style:italic;">
            System.Collections.ArrayList Contains() Method
            <br /> How to determine whether an element exists in ArrayList
        </h2>
        <hr width="550" align="left" color="Navy" />
        <br />
        <asp:Label
             ID="Label1"
             runat="server"
             ForeColor="DarkOliveGreen"
             Font-Size="Large"
             Font-Names="Courier New"
             Font-Italic="true"
             >
        </asp:Label>
        <br /><br />
        <asp:Button 
            ID="Button1"
            runat="server"
            OnClick="Button1_Click"
            Text="Test ArrayList Contains() Method"
            Height="45"
            Font-Bold="true"
            ForeColor="DodgerBlue"
            />
    </div>
    </form>
</body>
</html>
More asp.net examples