ArrayList IsFixedSize property in asp.net c#

ArrayList IsFixedSize Property
.Net framework ArrayList IsFixedSize property allow us to get a value indicating whether the ArrayList has a fixed size. the arraylist IsFixedSize property exists in System.Collections namespace. this property has no optional or required parameter.

arraylist IsFixedSize property return value type is System.Boolean. this property boolean value return 'true', if the arraylist has a fixed size; otherwise it returns 'false'. this property default value is 'false'. the arraylist IsFixedSize property implements as IList.IsFixedSize.

a fixed size arraylist does not allow the addition or removal of elements after the arraylist (collection) is created. but fixed size arraylist allow the modification (update) of existing elements.

the following asp.net c# example code demonstrate us how can we determine whether an arraylist has a fixed size programmatically at run time in an asp.net application.
ArrayListIsFixedSizeProperty.aspx

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

<!DOCTYPE html>

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

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

        ArrayList fixedSizeColors = ArrayList.FixedSize(colors);

        Label1.Text += "<br /><br />Is 'colors' ArrayList FixedSize? " + colors.IsFixedSize.ToString();
        Label1.Text += "<br />Is 'fixedSizeColors' ArrayList FixedSize? " + fixedSizeColors.IsFixedSize.ToString();

        colors.Add("Green");
        
        //Uncomment this line to get error message, because fixed size ArrayList does not support add/remove
        //fixedSizeColors.Add("Green");
        
        Label1.Text += "<br /><br /><font color=DodgerBlue>After Adding 'Green', Now 'colors' ArrayList Elements... ";
        foreach (string color in colors)
        {
            Label1.Text += "<br />" + color;
        }
        Label1.Text += "</font>";

        fixedSizeColors[1] = "Crimson";
        Label1.Text += "<br /><br />After modify 'index 1', Now 'fixedSizeColors' ArrayList Elements... <font color=DodgerBlue>";
        foreach (string color in fixedSizeColors)
        {
            Label1.Text += "<br />" + color;
        }
        Label1.Text += "</font>";
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>ArrayList IsFixedSize Property - How to get whether the ArrayList has a fixed size</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:MidnightBlue; font-style:italic;">
            System.Collections.ArrayList IsFixedSize Property
            <br /> How to get a value indicating whether
            <br /> the ArrayList has a fixed size
        </h2>
        <hr width="325" align="left" color="Navy" />
        <asp:Label
             ID="Label1"
             runat="server"
             ForeColor="HotPink"
             Font-Size="Large"
             Font-Names="Courier New"
             Font-Italic="true"
             Font-Bold="true"
             >
        </asp:Label>
        <br />
        <asp:Button 
            ID="Button1"
            runat="server"
            OnClick="Button1_Click"
            Text="Test ArrayList IsFixedSize Property"
            Height="45"
            Font-Bold="true"
            ForeColor="DodgerBlue"
            />
    </div>
    </form>
</body>
</html>
More asp.net examples