linq - How to get the average value from a numeric sequence

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>
More c# linq examples