c# - Lambda expression to return one result for each distinct value in list -


i have large list of class object , using following lambda function return elements meet condition.

var call = calllist.where(i => i.applicationid == 001).tolist(); 

this return list of objects have id of 001.

i curious different applicationids there are. lambda function list , return list element have different applicationid fetches 1 of those.

if understand question can try:

var list = calllist.groupby(x => x.applicationid).select(x => x.first()).tolist(); 

so if have list like:

appid:1, appid:1, appid:2, appid:2, appid:3, appid:3 

will return:

appid:1 appid:2 appid:3 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -