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