非常自我解释......
此:
{"hello","this","is","an","example","string"}
会回来:
{
{"is","an"},
{"this"},
{"hello"},
{"string"},
{"example"}
}
答案 0 :(得分:7)
您可以使用GroupBy
:
var groups = theList.GroupBy(i => i.Length);
答案 1 :(得分: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();
答案 2 :(得分:1)
GroupBy
字符串的长度:
var result = list.GroupBy(s => s.Length).Select(g => g.ToArray());
这将导致IEnumerable<string[]>
,其中每个字符串数组包含长度相同的字符串。品尝季节。