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..,
Post a Comment