string[] Words = new string[] { "what", "is", "your", "name", "?", "my", "name", "is", "lyf","." };
var Groups = from word in Words
group word by word.Length into lengthGroups //按单词长度将单词分组
orderby lengthGroups.Key descending //按单词长度降序排列
select new
{
Length = lengthGroups.Key, //取单词长度
WordCollect = lengthGroups //取该长度的单词分组集合
};
foreach (var group in Groups) //遍历每组单词
{
Response.Write("包含" + group.Length.ToString() + "个字符的单词有:" + "<br/>");
foreach (string word in group.WordCollect)
{
Response.Write(" " + word + "<br/>");
}
}