我如何确定列表中的每个对象都出现一次?
我写了一些查询 - 我想确保 retList 中的每个项目都会出现一次。 该查询获取集合“NamesItems”中与属性“Name”相同的所有名称,并返回名称和图片的集合(列表)。
我想确保 retList 中出现的每个名称都会出现一次。
我该怎么做?
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();
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();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 LINQ
Distinct
运算符来删除重复项。You can use the LINQ
Distinct
operator to remove duplicates.如果一个名称可以有多张图片,您需要在其中放置一个 group by 子句,然后执行诸如拍摄第一张照片之类的操作
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