Dotnet-StuffWorld

Monday, April 13, 2009

 

4. Total No. Of Birthdays each Year

4. Total No. Of Birthdays each Year: [part5]
To get a total of the employees born in the same year, use this query
C#
// Count people grouped by the Year in which they were born
var grpCountYrMon = empList.GroupBy(employees => employees.DOB.Year)
.Select(lst => new {Year = lst.Key, Count = lst.Count()} );

foreach (var employee in grpCountYrMon)
{
Console.WriteLine("\n{0} were born in {1}", employee.Count, employee.Year);
}
Console.ReadLine();
VB.NET
' Count people grouped by the Year in which they were born
Dim grpCountYrMon = empList.GroupBy(Function(employees) employees.DOB.Year).Select(Function(lst) New With {Key .Year = lst.Key, Key .Count = lst.Count()})

For Each employee In grpCountYrMon
Console.WriteLine(Constants.vbLf & "{0} were born in {1}", employee.Count, employee.Year)
Next employee
Console.ReadLine()

5. Sex Ratio
To find the sex ratio in the company, use this query
C#
// Sex Ratio
var ratioSex = empList.GroupBy(ra => ra.Sex)
.Select( emp => new
{
Sex = emp.Key,
Ratio = (emp.Count() * 100) / empList.Count
});

foreach (var ratio in ratioSex)
{
Console.WriteLine("\n{0} are {1}%", ratio.Sex, ratio.Ratio);
}
Console.ReadLine();
VB.NET ' Sex Ratio
Dim ratioSex = empList.GroupBy(Function(ra) ra.Sex).Select(Function(emp) New With {Key .Sex = emp.Key, Key .Ratio = (emp.Count() * 100) / empList.Count})

For Each ratio In ratioSex
Console.WriteLine(Constants.vbLf & "{0} are {1}%", ratio.Sex, ratio.Ratio)
Next ratio
Console.ReadLine()



finish..,

Comments:

Post a Comment

Subscribe to Post Comments [Atom]





<< Home

Archives

April 2009   July 2009   August 2009   September 2009   September 2010   February 2011  

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]