很不言自明...
这个:
{"hello","this","is","an","example","string"}
将返回:
{
{"is","an"},
{"this"},
{"hello"},
{"string"},
{"example"}
}
你可以使用GroupBy
:
var groups = theList.GroupBy(i => i.Length);
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();
GroupBy
字符串的长度:
var result = list.GroupBy(s => s.Length).Select(g => g.ToArray());
这将导致IEnumerable<string[]>
每个字符串数组包含具有相同长度的字符串。调味。