Dotnet-StuffWorld

Monday, April 13, 2009

 

2. List of Employees grouped by the Year in which they were Born

2. List of Employees grouped by the Year in which they were Born : [part3]
In order to group the employees based on the year in which they were born, use this query
C#
// Group People by the Year in which they were born
var grpOrderedYr = empList.GroupBy(employees => employees.DOB.Year).OrderBy(employees => employees.Key);

foreach (var employee in grpOrderedYr)
{
Console.WriteLine("\nEmployees Born In the Year " + employee.Key);
foreach (var empl in employee)
{
Console.WriteLine("{0,2} {1,7}", empl.ID, empl.FName);
}
}
Console.ReadLine();
VB.NET
' Group People by the Year in which they were born
Dim grpOrderedYr = empList.GroupBy(Function(employees) employees.DOB.Year).OrderBy(Function(employees) employees.Key)

For Each employee In grpOrderedYr
Console.WriteLine(Constants.vbLf & "Employees Born In the Year " & employee.Key)
For Each empl In employee
Console.WriteLine("{0,2} {1,7}", empl.ID, empl.FName)
Next empl
Next employee
Console.ReadLine()

cont..,

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]