CSharp · Script
using System;
using System.Collections.Generic;
using System.Linq;
class Employee { public int EmpID {get;set;} public string Name {get;set;} public DateTime DateofPresentation {get;set;} public List<Employee> Others {get;set;} }
List<Employee> employees = new List<Employee>()
{
new Employee { EmpID = 1 , Name ="AC", DateofPresentation = new DateTime(2013,12,24), Others = new List<Employee>()} ,
new Employee { EmpID = 1 , Name ="AC", DateofPresentation = new DateTime(2013,12,23), Others = new List<Employee>()},
new Employee { EmpID = 1 , Name ="AC", DateofPresentation = new DateTime(2013,12,22), Others = new List<Employee>()},
};
var all = employees
.GroupBy(x => x.EmpID)
.Select(g => {
var byPres = g.OrderByDescending(x => x.DateofPresentation).ToArray();
var e = byPres.First();
e.Others = byPres.Skip(1).ToList();
return e;
})
.ToList();
foreach (var e in all)
{
Console.WriteLine("Emp: {0}, Date: {1}", e.EmpID, e.DateofPresentation);
foreach (var o in e.Others)
{
Console.WriteLine("\tEmp: {0}, Date: {1}", o.EmpID, o.DateofPresentation);
}
}