Sort a List<string[]> by the second value (int)
This question already has an answer here:
var sortedList = listname.OrderBy(l => int.Parse(l[1]));
This assumes that the second entry in each array is parsable as int
. If you're not sure about that, you'd need to add some checks and maybe use int.TryParse
.
您可以在OrderBy
引用数组的适当索引:
var l = new List<string[]>() {
new string[] { "a", "b", "c" },
new string[] { "b", "a", "c" },
new string[] { "c", "c", "c" },
};
var s = l.OrderBy(c => c[1]).ToList();
链接地址: http://www.djcxy.com/p/70954.html
上一篇: 如何编写一个通用的排序扩展