cs_ShayW
Messages postés3258Date d'inscriptionjeudi 26 novembre 2009StatutMembreDernière intervention 3 décembre 2019
-
Modifié le 26 nov. 2018 à 21:02
Whismeril
Messages postés18417Date d'inscriptionmardi 11 mars 2003StatutContributeurDernière intervention 5 juin 2023
-
27 nov. 2018 à 07:18
Bonjour,
J'ai la class Info
public Class info
public name as string
public day as string
public thedate as string
end class
et
public listA as new list of(info)
private function FillListA as list of(info)
'bla bla
end function
public function Query as list of(info)
listA = FillListA()
dim listinfo = From evenement in listA where evenement.name .contains("toto") and evenement.day = "monday" and evenement.thedate = " 4 july" select evenement
return listinfo
end function</code >
déjà une erreur a la ligne <code>return listinfo
le correcteur marque
Return CType(listinfo, Global.System.Collections.Generic.List(Of info))
Mais quand je lance j'obtiens l'erreur
Unable to cast object of type 'WhereSelectListIterator`2[info,info]' to type 'System.Collections.Generic.List`1info]'.
merci d'avance
A voir également:
Unable to cast object of type 'whereselectlistiterator`2
Unable to cast object of type 'whereselectlistiterator - Meilleures réponses
cs_ShayW
Messages postés3258Date d'inscriptionjeudi 26 novembre 2009StatutMembreDernière intervention 3 décembre 201956 26 nov. 2018 à 22:07
public Class info
public name as string
public day as string
public thedate as string
end class
et
public listA as new list of(info)
private function FillListA as list of(info)
'bla bla
end function
public function Query as list of(info)
listA = FillListA()
dim listinfo = From evenement in listA where evenement.name .contains("toto") and evenement.day = "monday" and evenement.thedate = " 4 july" select evenement
return listinfo
end function
déjà une erreur a la ligne
return listinfo
le correcteur marque
Return CType(listinfo, Global.System.Collections.Generic.List(Of info))
Mais quand je lance j'obtiens l'erreur
Unable to cast object of type 'WhereSelectListIterator`2[info,info]' to type 'System.Collections.Generic.List`1info]'.
Whismeril
Messages postés18417Date d'inscriptionmardi 11 mars 2003StatutContributeurDernière intervention 5 juin 2023624 27 nov. 2018 à 07:18
Une requête linq retourne un IEnumerable(of. ) comme ta méthode est définie comme retournant une List(of ) listinfo doit être une List.
Il suffit donc de caster listinfo en List:
Return listinfo.ToList()
à condition bien sûr que ListA contienne des « info »
26 nov. 2018 à 22:14
On ne peut pas modifier le post original l'icon crayon "modifier" n'apparait pas