按最小值对列表列表进行排序

Mar*_*off 9 c# linq list

我试图按列表中的最小整数值对列表进行排序.这是我到目前为止的地方.

var SortedList = from lists in List 
                 orderby lists.List.Min(Min=>Min.value) 
                 ascending
                 select list ;
Run Code Online (Sandbox Code Playgroud)

例如:

var x = new List<int>{ 5, 10, 4, 3, 0 };
var y = new List<int> { 4, -1, -5, 3, 2 };
var z = new List<int> { 3, 1, 0, -2, 2 };

var ListofLists = new List<List<int>> {x, y, z};
Run Code Online (Sandbox Code Playgroud)

我的Linq的输出应该是,按列表列表中的最小值对列表进行排序.我的示例中的列表序列如下:

y - > z - > x

我尝试了很多linq表达式并在网上搜索.问题似乎很简单......感谢您提供任何帮助!

Cri*_*scu 12

它很简单:

var sorted = ListofLists.OrderBy(l => l.Min());
Run Code Online (Sandbox Code Playgroud)

或者,如果您更喜欢查询语法,则应该:

var sorted = from list in ListofLists 
             orderby list.Min()
             select list;
Run Code Online (Sandbox Code Playgroud)

在这里它是行动:https://dotnetfiddle.net/bnfGOG