c# - Find distinct values from a list of object by one field only -
how select distinct values list of objects? want list of specific field not list of whole object.
for example collection queried:
name year item1 2009 item2 2009 item3 2010 item4 2010 item5 2011 item6 2011
and want return distinct years below result collection
2009 2010 2011 2012
i tried
distinctyears = mycollection.groupby(x => x.year).select(x => x.first()).tolist();
but return collection of whole object instead of year values.
distinctyears = mycollection.select(x => x.year).distinct()
will return ienumerable<int>
(or whatever type year is)
no need grouping - want year in result, grab that.
Comments
Post a Comment