在Linq查询中对数组的元素进行排序?

时间:2014-06-29 16:20:24

标签: .net arrays vb.net linq sorting

我有一个List(of Integer())我希望对整数数组的元素进行排序,这一切都在一行中,问题是Array.Sort方法没有返回一个值然后会是一种有效的方式吗?

例如,我的列表包含第一个数组元素( MyArrayList.First )此数组:

{4, 5, 2, 6, 3, 1}

我需要对元素进行排序

{1, 2, 3, 4, 5, 6}

示例(不工作):

' Combos is the List(of Integer())
Combos = (From Combo As Integer() In Combos 
          Select Array.Sort(Combo)).ToList

3 个答案:

答案 0 :(得分:2)

这就是你要找的东西

    Combos.ForEach(Sub(x As Integer()) Array.Sort(x))

答案 1 :(得分:1)

一行:

Dim result = (From item As Integer() In list Select (From n As Integer In item Select n Order By n Ascending).ToArray()).ToList()

答案 2 :(得分:1)

为什么只想使用一条线?

For Each x In combos : Array.Sort(x) : Next
相关问题