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

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -