Yanshof
Yanshof

Reputation: 9926

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();

Upvotes: 0

Views: 67

Answers (2)

cadrell0
cadrell0

Reputation: 17327

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

Upvotes: 1

Martin Liversage
Martin Liversage

Reputation: 106906

You can use the LINQ Distinct operator to remove duplicates.

Upvotes: 3

Related Questions