ArrayList ToArray() method with data type in asp.net c#

ArrayList.ToArray() method with data type
ArrayListToArrayMethodWithType.aspx

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

<!DOCTYPE html>

<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        ArrayList favoriteColors = new ArrayList() { "White","FloralWhite","FireBrick","GoldenRod","LightCyan" };

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

        string[] favoriteColorArray = (string[])favoriteColors.ToArray(typeof(string));

        Label1.Text += "<br /><br />After Call ToArray(Type string) Method";
        Label1.Text += "<br />Array Elements....";
        Label1.Text += "<font color=MediumSlateBlue>";
        for (int i = 0; i < favoriteColorArray.Length; i++)
        {
            Label1.Text += "<br />" + favoriteColorArray[i];
        }
        Label1.Text += "</font>";
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>How to copy the elements of the ArrayList to a new array of the specified element type</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:MidnightBlue; font-style:italic;">
            System.Collections.ArrayList ToArray(Type) Method
            <br /> How to copy the elements of the ArrayList
            <br /> to a new array of the specified element type
        </h2>
        <hr width="450" align="left" color="Navy" />
        <br />
        <asp:Label
             ID="Label1"
             runat="server"
             ForeColor="DeepPink"
             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 ToArray(Type) Method"
            Height="45"
            Font-Bold="true"
            ForeColor="DodgerBlue"
            />
    </div>
    </form>
</body>
</html>
More asp.net examples