c# - Select Distinct rows based a particular column value in list -
i have following list lsit<car> lstcarip has following data
id | name | year 0 - zen - 1990 1 - alto - 2003 3 - zen - 2004 4 - santro - 2000 5 - alto - 2003 irrespective of id , year output list<car> lstfinal should have
id | name | year 0 - zen - 1990 1 - alto - 2003 4 - santro - 2000 or
id | name | year 3 - zen - 2004 4 - santro - 2000 5 - alto - 2003 ie if name occurs again 1 entry should added list<car> lstfinal . tried using lastordefault or groupby
lstfinal= lstcarip.groupby(s => s.name) .where(g => g.count() > 1) .selectmany(g => g) .tolist<car>(); but couldnt proper result. correct me , point mistake. help! :)
you groupby, , first
lstfinal = lstcarip.groupby(s => s.name) .select(g => g.first()) .tolist<car>();
Comments
Post a Comment