Bonjour à tous,

C'est la premiere fois que j'utilise IComparer et je ne comprends pas bien pourquoi dans mon cas ça ne fonctionne pas.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Public Class Employes
        Inherits System.Collections.Generic.List(Of Employe)

    Public Sub New()
      Load()
    End Sub
    Public Sub Load()
       While oDBDataReader.Read()
          Me.Add(charge(oDBDataReader))
       End While
    End Sub
    Public Sub TrieParNom() As System.Collections.Generic.List(Of Employe)
          Me.Sort(New CMySort())   
    End Function

      Class CMySort
            Implements System.Collections.IComparer
            Sub New()
            End Sub
            Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements _
            System.Collections.IComparer.Compare

                Dim E1 As Employe
                Dim E2 As Employe
                E1 = CType(x, Employe)
                E2 = CType(x, Employe)
                Return String.Compare(E1.Nom, E2.Nom)
            End Function
        End Class
End Class
Le compilateur me dit :
La résolution de surcharge a échoué, car aucun 'Sort' accessible ne peut être appelé avec ces arguments*:
'Public Sub Sort(comparison As System.Comparison(Of Employe))': Une valeur de type 'db.tables.employe.Employes.CMySort' ne peut pas être convertie en 'System.Comparison(Of db.tables.employe.Employe)'.
'Public Sub Sort(comparer As System.Collections.Generic.IComparer(Of Employe))': Option Strict On interdit les conversions implicites de 'db.tables.employe.Employes.CMySort' en 'System.Collections.Generic.IComparer(Of db.tables.employe.Employe)'.

merci d'avance pour votre aide.