Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.24 KB | None | 0 0
  1.  
  2. Private Sub SortMethod()
  3.     Dim table As New List(Of List(Of Integer))()
  4.     FillTable(table)
  5.  
  6.     PrintList(table)
  7.  
  8.     Const  firstSortColumn As Integer = 1
  9.     Const  secondSortColumn As Integer = 0
  10.     Const  thirdSortColumn As Integer = 2
  11.  
  12.     Dim tableAfterFirstSorting As IOrderedEnumerable(Of List(Of Integer)) = table.OrderBy(Function(o) o(firstSortColumn))
  13.  
  14.     Dim tableAterSecondSorting As IOrderedEnumerable(Of List(Of Integer)) = tableAfterFirstSorting.ThenBy(Function(o) o(secondSortColumn))
  15.  
  16.     Dim tableAfterThirdSorting As IOrderedEnumerable(Of List(Of Integer)) = tableAterSecondSorting.ThenBy(Function(o) o(thirdSortColumn))
  17.  
  18.  
  19.     PrintList(tableAfterThirdSorting.ToList())
  20. End Sub
  21.  
  22. Private Sub FillTable(table As List(Of List(Of Integer)))
  23.     Dim rnd As New Random()
  24.     For y As Integer = 0 To 9
  25.         Dim column As New List(Of Integer)()
  26.         For x As Integer = 0 To 2
  27.             column.Add(rnd.[Next](4))
  28.         Next
  29.         table.Add(column)
  30.     Next
  31. End Sub
  32.  
  33. Private Sub PrintList(table As List(Of List(Of Integer)))
  34.     Dim output As String = ""
  35.     For Each row As List(Of Integer) In table
  36.         output = row.Aggregate(output, Function(current, cell) current + (cell + " "))
  37.         output += vbLf
  38.     Next
  39.     output += "=========================" & vbLf
  40.     MessageBox.Show(output)
  41. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement