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
Post a Comment