list 排序 orderBy
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim stuList As New List(Of Student)() From { _
New Student() With {.Score = 90, .Name = "Tim", .Age = 29}, _
New Student() With {.Score = 98, .Name = "Tom", .Age = 28}, _
New Student() With {.Score = 98, .Name = "Tomi", .Age = 23}, _
New Student() With {.Score = 82, .Name = "Kyle", .Age = 27}, _
New Student() With {.Score = 76, .Name = "Tony", .Age = 26}, _
New Student() With {.Score = 96, .Name = "moly", .Age = 39}, _
New Student() With {.Score = 86, .Name = "Tkiy", .Age = 29}, _
New Student() With {.Score = 97, .Name = "Vina", .Age = 25}, _
New Student() With {.Score = 95, .Name = "Mike", .Age = 24}, _
New Student() With {.Score = 95, .Name = "Coki", .Age = 29} _
}
Dim list1 As List(Of Student) = stuList.OrderBy(Function(t) t.Score).ThenBy(Function(x) x.Age).ToList()
'升序OrderBy
'降序OrderByDescending()
Dim ss As String = ""
For Each S As Student In list1
ss &= S.Name & " A" & S.Age & " S" & S.Score & vbCrLf
Next
MsgBox(ss)
'升序
Dim list2 As List(Of Student) = stuList.OrderByDescending(Function(t) t.Score).ThenByDescending(Function(x) x.Age).ToList()
Dim ss1 As String = ""
For Each S As Student In list2
ss1 &= S.Name & " A" & S.Age & " S" & S.Score & vbCrLf
Next
MsgBox(ss1)
End Sub
End Class
Public Class Student
Public Property Score() As Double
Public Property Name() As String
Public Property Age() As Integer
End Class
Please follow WeChat's public account ByCAD