Dotnet-StuffWorld

Monday, April 13, 2009

 

3. List of employees grouped by the Year and Month in which they were born

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..,

Comments:
some of the code helped me
 
but some of the code has long step,should i optimize the code..
 

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]