我正在寻找的语言是 MS Visual Basic。
如何对数组进行排序并相应地更改其他数组(使用索引?)
我正在搜索,但找不到任何东西。任何帮助是极大的赞赏!!!
例如对数组 BirthArray 进行排序并相应地更改 Array1 和 ID 的顺序?
Array1 = 'John', 'Christina','Mary', 'frediric', 'Johnny','billy','mariah'
BirthArray = 1998, 1923, 1983,1982,1924,1923,1954
ID = 12312321, 1231231209, 123123, 234324, 23423, 2234234,932423
Dim Array() As String
Dim BirthArray() As Integer
Dim ID() As Integer
非常感谢!
最佳答案
您应该创建一个类来保存值,将这些类的集合放入一个列表中,然后使用 lambda 表达式对列表进行排序:
Public Class Info
Public Property Name As String
Public Property BirthYear As Integer
Public Property ID As Integer
Public Sub New()
End Sub
Public Sub New(sName As String, wBirthYear As Integer, wID As Integer)
Me.New
Me.Name = sName
Me.BirthYear = wBirthYear
Me.ID = wID
End Sub
End Class
Public Sub DoSort()
Dim cRecords As New System.Generic.List(Of Info)
cRecords.Add(New Info('John', 1998, 12312321)
' ToDo: Add more records
cRecords.Sort(
Function (ByVal oItem1 As Info, ByVal oItem2 As Info)
Return oItem2.BirthYear.CompareTo(oItem1.BirthYear)
End Function)
End Sub
关于sorting - MS Visual Basic 如何对 1 个数组进行排序并返回第二个数组的索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8620427/