如何使用Linq按字符串长度对List<string>
数组进行排序?执行效率无关紧要。
List<string>[] col = new List<string>[]
{
new List<string>(){"aaa", "bbb"},
new List<string>(){"a", "b", "d"},
new List<string>(){"xy","sl","yy","aq"}
}; //Each string in a list of strings of a particular array element has equal length.
排序后应生成
{&#34; a&#34;,&#34; b&#34;,&#34; d&#34;},{&#34; xy&#34;,&#34; sl&#34; ,&#34; yy&#34;,&#34; aq&#34;},{&#34; aaa&#34;,&#34; bbb&#34;}
答案 0 :(得分:5)
答案 1 :(得分:1)
如果您要整理现有的 col
列表(即就地排序):
col.Sort((left, right) = > left[0].Length.CompareTo(right[0].Length));
然而,这不是 Linq 。
答案 2 :(得分:0)