برای استفاده از generic collections ممکن است که نیاز به رابط هایی داشته باشم
مانند Sort کردن ListArray که نیاز به IComparable دارد.
این مبحث را فردا کامل میکنم
Public Class person
Implements IComparable
Private firstName As String
Private lastName As String
Public Function CompareTo(ByVal obj As Object) _
As Integer Implements System.IComparable.CompareTo
Dim otherPerson As person = DirectCast(obj, person)
If Me.lastName <> otherPerson.lastName Then
Return Me.lastName.CompareTo(otherPerson.lastName)
Else
Return Me.firstName.CompareTo(otherPerson.firstName)
End If
End Function
Public Sub New(ByVal _firstName As String, ByVal _lastName As String)
firstName = _firstName
lastName = _lastName
End Sub
Public Overrides Function ToString() As String
Return firstName + " " + lastName
End Function
End Class
Dim l As New List(Of person)()
l.Add(New person("Mark", "Hanson"))
l.Add(New person("Kim", "Akers"))
l.Add(New person("Zsolt", "Ambrus"))
l.Sort()
For Each p As person In l
Console.WriteLine(p.ToString())
Next