Linq Average Operator - How to get the average of a sequence of numeric values
LinqAverageOperator.aspx
<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Linq" %>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
int[] prices = {21,23,29,18,33,27,29};
double averagePrice = prices.Average();
Label1.Text = "Price List: <br />";
foreach (int n in prices)
{
Label1.Text += n.ToString() + "<br />";
}
Label2.Text = "Average Price: " + averagePrice.ToString() +"<br />";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Linq Average Operator - How to get the average of a sequence of numeric values</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:DarkBlue; font-style:italic;">
Linq Standard Query Operator - Average
<br />How to get the average of a
<br /> sequence of numeric values
</h2>
<hr width="375" align="left" color="CornFlowerBlue" />
<asp:Label
ID="Label1"
runat="server"
Font-Size="Large"
ForeColor="Crimson"
Font-Italic="true"
>
</asp:Label>
<br />
<asp:Label
ID="Label2"
runat="server"
Font-Size="Large"
ForeColor="DodgerBlue"
Font-Italic="true"
>
</asp:Label>
<br />
<asp:Button
ID="Button1"
runat="server"
OnClick="Button1_Click"
Text="Test Linq Query Operator - Average"
Height="45"
Font-Bold="true"
ForeColor="DodgerBlue"
/>
</div>
</form>
</body>
</html>
- linq - How to get difference between two sequences
- linq - How to get intersection of two sequences
- How to convert Linq query result to a List
- linq - How to union two sequences
- linq - How to create an XML declaration for a document
- linq - How to create an XML document
- linq - How to create an XML element
- linq - How to count occurrences of a string within a string
- LINQ to remove objects within a List
- linq - How to sort a date list order by ascending descending