Istudent Rana

Istudent Rana

  • 1.4k
  • 342
  • 84k

how do i create new object out of list of object using linq

Apr 1 2020 10:56 AM
I do have a list of employee objects which can be 'group by'  by employee id.
 
List<EmployeeHour> employeeHours = new List<EmployeeHour>
{
new EmployeeHour{Id = 1, EmployeeName = "Emp1", Day = 1, Hours = 6},
new EmployeeHour{Id = 1, EmployeeName = "Emp1", Day = 2, Hours = 8},
new EmployeeHour{Id = 2, EmployeeName = "Emp2", Day = 1, Hours = 6},
new EmployeeHour{Id = 2, EmployeeName = "Emp2", Day = 2, Hours = 8}
};
 
I want to create list of object something like 
 
new {
   Id = 1,
   EmplyeeName = Emp1,
   Day1 = 6,
   Day2 = 8
},
new {
   Id = 2,
   EmplyeeName = Emp2,
   Day1 = 6,
   Day2 = 8
}
 
 

Answers (5)