实例:
String[] ssss = new
String[] { "2011/3", "2011/2", "2011/5", "2012/5" };
//排序方式一:使用扩展方法
IEnumerable<String> query =
ssss.OrderBy(x => x);
//排序方式二:
var
sortedWords = from s in ssss
orderby
s ascending //或descending
select
s;
排序前顺序:
2011/3
2011/2
2011/5
2012/4
方式一排序后顺序:
2011/2
2011/3
2011/5
2012/4
方式二排序后顺序:
2011/2
2011/3
2011/5
2012/4
技术说明:
命名空间: System.Linq
程序集: System.Core(在 System.Core.dll
中)
静态方法:
//
// 摘要:
//
根据键按升序对序列的元素排序。
//
// 参数:
// source:
//
一个要排序的值序列。
//
// keySelector:
//
用于从元素中提取键的函数。
//
// 类型参数:
// TSource:
//
source 中的元素的类型。
//
// TKey:
//
keySelector 返回的键的类型。
//
// 返回结果:
//
一个
System.Linq.IOrderedEnumerable<TElement>,其元素按键排序。
//
// 异常:
//
System.ArgumentNullException:
//
source 或 keySelector 为 null。
public static
IOrderedEnumerable<TSource>
OrderBy<TSource, TKey>(this
IEnumerable<TSource> source,
Func<TSource, TKey> keySelector);
加载中,请稍候......