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:
Now, double click on Display Record button and write the following code:-
Now run the application and click on Display Record button and get output.
Now, we add the Default.aspx page and write the following code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
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.