如何使用 Linq 对结果进行排序和排序
我有日期时间值(例如 12/01/2010 10:10:222..) 如何按降序顺序仅显示年份?例如,2011、2010、2009、2008 等。我需要仅按字段的年份部分进行分组并返回。我实际上需要返回年份和名称。我需要将该名称用于其他功能,这就是我需要这两个值的原因。
感谢您的帮助...
I have datetime values (e.g. 12/01/2010 10:10:222..) How can I display just the year in desc order? For example, 2011, 2010, 2009, 2008, etc.. I need to group by just the year part of the field and return that. I actually need to return the year and the name. I need to use the name for other functionality, which is why I need the 2 values.
Thanks for any help...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
目前尚不清楚您的意思,但您可能只是想要这样的内容:
如果这不是您想要的,请提供更多详细信息 - 最好是一些示例输入和所需的输出。
如果您只想要每个组中的一个条目,并且您很乐意任意选择一个条目来获取名称,并且您只想要年份,那么您可以这样做:
It's not really clear what you mean, but you might just want something like:
If that's not what you're after, please provide more details - ideally some sample input and desired output.
If you only want one entry from each group and you're happy to take any arbitrary one to get the name, and you only want the year, you could do:
我将使用 Distinct 和 OrderByDescending 扩展:
I would use the Distinct and OrderByDescending extensions: