Generic List Count property in asp.net c#

Generic List Count Property
.Net framework generic list Count property allow us to get the number of elements contained in the List<T>. the List class Count property exists in under System.Collections.Generic namespace. the Count property value data type is System.Int32. this integer value represents the number of elements exists in generic list.

this property implements as ICollection<T>.Count, IReadOnlyCollection<T>.Count and ICollection.Count. List class Count property return the number of elements that are actually exists in the list.

the following asp.net c# example code demonstrate us how can we count the generic list elements programmatically at run time in an asp.net application.
GenericListCount.aspx

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        List<string> colors = new List<string>();
        colors.Add("DarkCyan");
        colors.Add("DarkGray");
        colors.Add("Cornsilk");
        colors.Add("DarkOliveGreen");
        colors.Add("DimGray");

        Label1.Text = "Total List Elements? " + colors.Count;

        RadioButtonList1.DataSource = colors;
        RadioButtonList1.DataBind();
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Generic List Count - How to Get the number of elements actually contained in the List</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:OliveDrab; font-style:italic;">
            System.Collections.Generic.List Count Property
            <br /> How to Get the number of elements actually contained in the List
        </h2>
        <hr width="625" align="left" color="Olive" />
        <asp:Label
             ID="Label1"
             runat="server"
             ForeColor="DarkOrchid"
             Font-Names="Courier New"
             Font-Size="X-Large"
             >
        </asp:Label>
        <br /><br />
        <asp:RadioButtonList
             ID="RadioButtonList1"
             runat="server"
             BorderWidth="2"
             BorderColor="ForestGreen"
             BorderStyle="Dashed"
             Font-Names="Comic Sans MS"
             Font-Italic="true"
             ForeColor="Snow"
             BackColor="DarkSeaGreen"
             Width="425"
             RepeatColumns="2"
             >
        </asp:RadioButtonList>
        <br />
        <asp:Button 
            ID="Button1"
            runat="server"
            OnClick="Button1_Click"
            Text="Create Generic List And Count List Elements"
            Height="45"
            Font-Bold="true"
            ForeColor="DodgerBlue"
            />
    </div>
    </form>
</body>
</html>
Related asp.net examples