ArrayList AddRange() method in asp.net c#

ArrayList AddRange()
.Net framework ArrayList AddRange() method allow us to add the elements of an ICollection to the end of the ArrayList. this arraylist AddRange() method exists under System.Collections namespace.

this method require to pass a parameter named 'c'. the 'c' parameter type is System.Collections.ICollection, which represents the ICollection whose elements should be added to the end of the arraylist. the collection itself cannot be null, but it can contain elements that are null.

the AddRange() method throw ArgumentNullException exception, if the 'c' is null. this method also throw NotSupportedException, if the ArrayList is read-only or the ArrayList has a fixed size. arraylist accepts duplicate values.

the following asp.net c# example code demonstrate us how can we add a collection of elements to the end of an arraylist programmatically at run time in an asp.net application.
ArrayListAddRangeMethod.aspx

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

<!DOCTYPE html>

<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        ArrayList colors = new ArrayList() {"Green","SeaGreen","SpringGreen"};

        List<string> redColors = new List<string>{"Red","IndianRed","DarkRed"};

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

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>ArrayList AddRange() - How to add the elements of an ICollection to the end of the ArrayList</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:MidnightBlue; font-style:italic;">
            System.Collections.ArrayList AddRange() Method
            <br /> How to add the elements of an ICollection to the end of the ArrayList
        </h2>
        <hr width="725" align="left" color="Navy" />
        <br />
        <asp:Label
             ID="Label1"
             runat="server"
             ForeColor="SeaGreen"
             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 AddRange() Method"
            Height="45"
            Font-Bold="true"
            ForeColor="DodgerBlue"
            />
    </div>
    </form>
</body>
</html>
More asp.net examples