-1

很不言自明...

这个:

{"hello","this","is","an","example","string"}

将返回:

{
    {"is","an"},
    {"this"},
    {"hello"},
    {"string"},
    {"example"}
}
4

3 回答 3

7

你可以使用GroupBy

var groups = theList.GroupBy(i => i.Length);
于 2013-04-29T20:47:53.443 回答
2
List<string> list = new List<string>() { "hello", "this", "is", "an", "example", "string" };
var listOfLists = list.GroupBy(s => s.Length)
                      .OrderBy(g => g.Key)
                      .Select(g => g.ToList())
                      .ToList();
于 2013-04-29T20:48:39.807 回答
1

GroupBy字符串的长度:

var result = list.GroupBy(s => s.Length).Select(g => g.ToArray());

这将导致IEnumerable<string[]>每个字符串数组包含具有相同长度的字符串。调味。

于 2013-04-29T20:47:55.207 回答