I have following collection:
public IList<Emp> EmpList()
{
IList<Emp> empList = new List<Emp>();
empList.Add(new Emp() { Id = 1, Name = "abc1" });
empList.Add(new Emp() { Id = 1, Name = "abc2" });
empList.Add(new Emp() { Id = 2, Name = "abc3" });
empList.Add(new Emp() { Id = 2, Name = "abc4" });
empList.Add(new Emp() { Id = 4, Name = "abc5" });
return empList;
}
I wants to get distinct records based on Id from the EmpList()
collection. I mean first row, third row and last row from the EmpList()
collection.
Any help would be greatly appreciated.
Edit-var empList = emp.EmpList().GroupBy(x => x.Id).Select(x => x.First());
This query is working fine for the solution.