string[] fruits = { "grape", "passionfruit", "banana", "mango",
"orange", "raspberry", "apple", "blueberry" };
// Sort the strings first by their length and then
//alphabetically by passing the identity selector function.
IEnumerable<string> query =
fruits.OrderBy(fruit => fruit.Length).ThenBy(fruit => fruit);
如果我们需要更多的订货比它是可能的,以OrderBy
单呼,那么我们就应该继续调用ThenBy
代替排序依据,因为通过ThenBy
进行的排序是稳定的,因此保留了使用相同的键值对输入元素进行排序。排序依据,ThenBy和IOrderedEnumerable <T>
a)在上面的例子中OrderBy
返回IOrderedEnumerable<>
序列ř并反过来ThenBy
被称为该序列。当OrderBy
返回ř,确实ř还存储其中使用由OrderBy
在ř元素进行排序的关键值(fruit.Length
值)?
b)哪里在R是存储的关键值?
谢谢
您是否想过'GroupBy'? – mellamokb 2011-05-02 18:39:32
我正在考虑OrderBy – flockofcode 2011-05-02 19:16:30