Using the Aggregate operators
The Aggregate operates are used to calculate a value. The Aggregate function returns only a single value. The different Aggregate operators are Count, Sum, Min, Max, Average, and Aggregate.



Now, we add the Default.aspx page and write the following code:

  

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <center> 
    <div>
        <h1>Using the Aggregate operators</h1>
        <asp:ListBox ID="lbDetail" runat="server" Height="350px" Width="500px"></asp:ListBox> <br /> <br />
        <asp:Button ID="btnDisplayRecord" runat="server" Text="Display Record" Font-Bold="true" OnClick="btnDisplayRecord_Click" />
    
    </div>
            </center>
    </form>
</body>
</html>




Now, double click on Display Record button and write the following code:-

  

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnDisplayRecord_Click(object sender, EventArgs e)
    {
        lbDetail.Items.Clear();

        int[] Numbers = { 10, 20, 25, 5, 26, 21, 40, 50, 67, 86, 80, 33, 30, 18 };
        int oddNum = Numbers.Count(n => n % 2 == 1);
        lbDetail.Items.Add("The count odd numbers are= "+oddNum);
        int MinNum = Numbers.Min();
        lbDetail.Items.Add("The Minimum Number is  =" + MinNum);

        int MaxNum = Numbers.Max();
        lbDetail.Items.Add("The Maximum Number is = " + MaxNum);

        double sum = Numbers.Sum();
        lbDetail.Items.Add("The Sum of the Numbers is = " + sum);

        double avg = Numbers.Average();
        lbDetail.Items.Add("The Average of the Numbers is = " + avg);
        
    }

}



Now run the application and click on Display Record button and get output.