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 32 33 34 35
| Dim Ecole As New Dictionary(Of String, List(Of cEleve))
Dim sats As New List(Of cEleve)
sats.Add(New cEleve With {.nom = "Luc", .age = 5})
sats.Add(New cEleve With {.nom = "Pierre", .age = 4})
sats.Add(New cEleve With {.nom = "Michel", .age = 4})
Ecole.Add("CM1A", sats)
sats = New List(Of cEleve)
sats.Add(New cEleve With {.nom = "Anne", .age = 6})
sats.Add(New cEleve With {.nom = "Louis", .age = 5})
Ecole.Add("CM1B", sats)
sats = New List(Of cEleve)
sats.Add(New cEleve With {.nom = "Lucie", .age = 3})
sats.Add(New cEleve With {.nom = "Vally", .age = 3})
Ecole.Add("CE2A", sats)
Dim sRecherche As String = "Pierre"
'lourd mais ça fonctionne....
Dim Eleve As cEleve = Ecole.Values.First(Function(x) x.Exists(Function(k) k.nom = sRecherche)).First(Function(y) y.nom = sRecherche)
If Not IsNothing(Eleve) then
Dim sClasse As String = Ecole.First(Function(x) x.Value.Exists(Function(k) k.nom = sEleve)).Key
MsgBox(Eleve.nom & " a " & Eleve.age & " ans et est en classe de " & sClasse)
End If
End Sub
End Class
Public Class cEleve
Public Property nom As String
Public Property age As Integer
End Class |
Partager