Also, mein erstes Posting enthält eigentlich ein gutes Beispiel, aber hier noch mal ein ganz einfaches:
Code:
Public Class Form1
Public Class myCMPClass
Implements IComparer
Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements IComparer.Compare
Dim s1() As String = x.split(" ")
Dim s2() As String = y.split(" ")
Return Integer.Parse(s1(0)).CompareTo(Integer.Parse(s2(0)))
End Function
End Class
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim s(3) As String
s(0) = "473 hallo"
s(1) = "123 abc"
s(2) = "54 wtf"
s(3) = "883 hoi"
Array.Sort(s, new myCMPClass)
For Each t As String In s
MessageBox.Show(t)
Next
End Sub
End Class
Das Ergebnis ist:
54 wtf
123 abc
473 hallo
883 hoi
Beim "normalen" Sortieren wäre das Ergebnis:
123 abc
473 hallo
54 wtf
883 hoi