LINQ To SQL: Sum operator

EmpDetails Table:

LinqTable.png


Code:


To Compute the Sum of Values in a Numeric Sequence


using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
namespace
LINQ
{
class Program
{
static void Main(string[] args)
{
DataClassesDataContext dc = new DataClassesDataContext();
var allowance = (from emp in dc.EmpDetails
                 select emp.Allowance).Sum();
Console.WriteLine(allowance);
Console.Read();
}
}
}

Output:

24100
Ebook Download
View all
Learn
View all