3. List of employees grouped by the Year and Month in which they were born: [part4]In order to group the employees based on the year and then the month in which they were born, use this query
C#
// Group people by the Year and Month in which they were born
var grpOrderedYrMon = empList.GroupBy(employees =>
new DateTime(employees.DOB.Year, employees.DOB.Month, 1)).OrderBy(employees => employees.Key); ;
foreach (var employee in grpOrderedYrMon)
{
Console.WriteLine("\nEmployees Born in Year {0} - Month {1} is/are :", employee.Key.Year, employee.Key.Month);
foreach (var empl in employee)
{
Console.WriteLine("{0}: {1}", empl.ID, empl.FName);
}
}
Console.ReadLine();
VB.NET
' Group people by the Year and Month in which they were born
Dim grpOrderedYrMon = empList.GroupBy(Function(employees) New DateTime(employees.DOB.Year, employees.DOB.Month, 1)).OrderBy(Function(employees) employees.Key)
For Each employee In grpOrderedYrMon
Console.WriteLine(Constants.vbLf & "Employees Born in Year {0} - Month {1} is/are :", employee.Key.Year, employee.Key.Month)
For Each empl In employee
Console.WriteLine("{0}: {1}", empl.ID, empl.FName)
Next empl
Next employee
Console.ReadLine()
Cont..,
Post a Comment