LINQ 2 对象 - 如何选择不同的对象?
我有一个对象集合,它们是: 某个日期 someString
我需要选择这两个字段不同的对象。 我无法选择它作为集合中的对象 - 我需要创建新的对象。
说:
01/01/2011“一”
01/01/2011“一”
01/01/2011“一”
01/01/2011“二”
(我需要注意 - 这四个彼此不同)
并且我需要获得:
01/01/2011 “一”
01/01/2011 “二”
我怎样才能实现它?
谢谢。
I have a collection of objects which are:
someDate
someString
I need to select objects that are different by this two fields.
And I can not select it as objects in collections - I need to create new ones.
Say:
01/01/2011 "One"
01/01/2011 "One"
01/01/2011 "One"
01/01/2011 "Two"
(I need to note - this four are different to each other)
And I need to get:
01/01/2011 "One"
01/01/2011 "Two"
How can I achieve it?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的问题相当不清楚,但听起来您要么只需要在投影后使用
Distinct
:或者您需要使用类似< code>DistinctBy 来自 MoreLINQ:
如果您能澄清的话,将会真正有所帮助不过你的问题。
Your question is fairly unclear, but it sounds like you either just need to use
Distinct
after a projection:or you need to use something like
DistinctBy
from MoreLINQ:It would really help if you could clarify your question though.