How can i be sure that each of the objects in the List appears once?
I wrote some query - and i want to be sure that each item in the retList will appear once. The query get all the names that are same as property 'Name' in the collection 'NamesItems' and return at the a collection ( list ) of the name and the picture .
I want to be sure that each name that will appear in the retList will appear once.
How can i do it ?
List<NameVIewItem> retList = null;
IEnumerable<ItemT> u = NamesItems.Where( x => x.Name == Name );
retList = ( from t in ItemsCollection
join o1 开发者_开发问答in u on t.Key equals o1.Name2
select new NameViewITem ( o1.Key, t.Picture ), o1.Name )).ToList();
You can use the LINQ Distinct
operator to remove duplicates.
If one Name can have multiple Pictures, you will need to put a group by clause in there, then do something like take the first picture
精彩评论