通过排序多个字段集合 [英] Sorting a collection by multiple fields

查看:192
本文介绍了通过排序多个字段集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要排序的集合。
为例,我有

I need to sort a collection. For example, I have

Austin 12/3/2012   
Sam 100 12/3/2012   
Sam 200 14/3/2012   
Bubly 300 12/3/2012   
Bubly 300 15/3/2012  
ram 100 13/3/2012 

现在,如果排序顺序是名称,日期时间
,则输出应

Now if the sort order is Name, datetime then output should be

Austin 12/3/2012    
Bubly 12/3/2012   
Bubly 15/3/2012   
ram 13/3/2012    
sam 12/3/2012    
sam 14/3/2012  

如果他排序顺序日期时间,名称,然后
应该是

If he sort order is Datetime , Name then it should be

12/3/2012 austin
12/3/2012 bubly
12/3/2012 sam
13/3/2012 ram
14/3/2012 sam
15/3/2012 bubly 

因此其他项目。我该怎么做呢?我如何采取列的顺序进行排序

Accordingly for other items. How do i do this ? How do I take the order of columns for sorting.

推荐答案

您可以使用LINQ功能的 ThenBy 使用的排序依据以进行进一步的分类。

You can use Linq function ThenBy after using OrderBy to perform further sorting.

listOfRecords.OrderBy(p => p.Name).ThenBy(p => p.Date)

这篇关于通过排序多个字段集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆