Linq Sum Operator - How to get sums the numbers in a sequence
LinqSumOperator.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 = {125,442,21,89,142,334,19};
Label1.Text = "Price List: <br />";
foreach (int n in prices)
{
Label1.Text += n.ToString() + "<br />";
}
Label2.Text = "Sum of the Prices: " + prices.Sum().ToString(); ;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Linq Sum Operator - How to get sums the numbers in a sequence</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:DarkBlue; font-style:italic;">
Linq Standard Query Operator - Sum
<br />How to get sums the numbers in a sequence
</h2>
<hr width="425" align="left" color="CornFlowerBlue" />
<asp:Label
ID="Label1"
runat="server"
Font-Size="X-Large"
ForeColor="DarkOrchid"
Font-Italic="true"
>
</asp:Label>
<br />
<asp:Label
ID="Label2"
runat="server"
Font-Size="X-Large"
ForeColor="SeaGreen"
Font-Italic="true"
>
</asp:Label>
<br /><br />
<asp:Button
ID="Button1"
runat="server"
OnClick="Button1_Click"
Text="Test Linq Query Operator - Sum"
Height="45"
Font-Bold="true"
ForeColor="DodgerBlue"
/>
</div>
</form>
</body>
</html>

- linq - How to sort elements of a sequence in ascending order
- How to use linq select query
- linq - How to determine if all items in a sequence match condition
- linq - How to get a sequence without duplicate items
- linq - How to reverse the order of elements in a sequence
- linq - How to get element at a specified index in a sequence
- linq - How to get the first element of a sequence
- linq - How to get first element of a sequence or a default value
- linq - Get first element of a sequence that match condition or a default value
- linq - How to get the last element of a sequence