驗證碼:我在哪裏把「orderby group.key」放在這個LINQ語句中?
string[] words = {"car", "boy", "apple", "bill", "crow", "brown"};
var groups = from w in words
group w by w[0] into g
select new {FirstLetter = g.Key, Words = g};
//orderby ???;
var wordList = groups.ToList();
//var wordList = groups.ToList().OrderBy(???);
wordList.ForEach(group =>
{
Console.WriteLine("Words that being with {0}:",
group.FirstLetter.ToString().ToUpper());
foreach(var word in group.Words)
Console.WriteLine(" " + word);
});
輸出這樣:
Words that being with C:
car
crow
Words that being with B:
boy
bill
brown
Words that being with A:
apple
但我在哪裏把排序依據語句,以便它以字母順序列出了呢?
是的,這是我很感謝 – 2009-11-05 09:54:13