Q:

Vb, sorting lists

I have a question concerning sorting lists of classes in VB.Net.  
It seems every subject which is discussing this kind of sorting is not really clear for me. 
I have a class Language with the following variables:
- Lang as a string
- Knowledge as a integer
I have got a list containing a couple of language classes in it.  How can I sort on the Lang variable (Alphabetically sort the language classes in the list)? 
Greetings,

A:

Implement IComparable on your class, then use Sort:
Private Class Language : Implements IComparable(Of Language)
  Public Property Lang As String
  Public Property Knowledge As Integer

  Sub New(lang As String)
    Me. Lang = lang
  End Sub

  Public Function CompareTo(other As Language) As Integer _
                                    Implements IComparable(Of Language).CompareTo
    Dim comp As Integer = Me. Lang. CompareTo(other. Lang)
    'If comp = 0 Then Return Me. Knowledge. CompareTo(other. Knowledge)
    Return comp
  End Function
End Class

Sub Main()
  Dim lst As New List(Of Language)
  lst. Add(New Language("fr"))
  lst. Add(New Language("en"))
  lst. Add(New Language("de"))
  lst. Sort()
End Sub

EDIT: Added a hint on how to sort by multiple properties.