assume I have the following object
public class DepartmentSchema
{
public int Parent { get; set; }
public int Child { get; set; }
}
and I have a List<DepartmentSchema>
with the following results:
Parent | Child
---------------
4 | 1
8 | 4
5 | 7
4 | 2
8 | 4
4 | 1
I want to group all the objects that has the same parent value AND child value After the grouping what I want in result is the following list
Parent | Child
---------------
4 | 1
8 | 4
5 | 7
4 | 2
I manage to success using IGrouping =>
departmentSchema.GroupBy(x => new { x.Parent, x.Child }).ToList();
but the result wereList<IGrouping<'a,DepartmentSchema>>
instead of List<DepartmentSchema>
I know I can make a new foreach loop and create a new List<DepartmentSchema>
from the group list but I wonder if there is any better way
Thanks in advance