2013-07-09 1 views
0

Comment puis-je retourner un IEnumerator d'un SortedDictionary(Of Integer, MyClass)VB.Net IEnumerator (Of Integer, MyClass) n'est pas possible?

Je cela.

Dim dictionaryTest As New SortedDictionary(Of Integer, MyClass) 
Dim enumerator As IEnumerator(Of Integer, MyClass) = dictionaryTest.GetEnumerator() '<- not possible. 

Je veux une fonction comme

public function getTestEnumerator() as IEnumerator(Of Integer, MyClass) 
    return dictionaryTest.GetEnumerator() 
end function 

erreur généré en IDE
'System.Collections.IEnumerator' has no type parameters and so cannot have type arguments.

+1

Avez-vous importé l'espace de noms 'System.Collections.Generic'? Aussi je crois qu'il est en fait un 'IEnumerator (de KeyValuePair (Of Integer, Myclass))' –

+0

Cela fonctionne parfaitement c'était 'Of KeyValuePair (...)' ce qui me manquait. Étrange pourquoi je ne dois pas utiliser 'KeyValuePair' pour' SortedDictionary' mais j'en ai besoin pour 'GetEnumerator()'. Je l'ai laissé juste 'IEnumerator' semble également fonctionner – SSpoke

+0

N'ont pas importé le' System.Collections.Generic' toujours pas d'erreurs ou d'avertissements du compilateur. Je n'ai pas besoin de cette bibliothèque Je pense que 'Imports System.Collections' fonctionne mais peut-être que j'importe tout n'est pas sûr – SSpoke

Répondre

0
Dim dictionaryTest As New SortedDictionary(Of Integer, MyClass) 

réponse est remplacer

Dim enumerator As IEnumerator(Of Integer, MyClass) = dictionaryTest.GetEnumerator() '<- not possible. 

avec

Dim enumerator As IEnumerator(Of KeyValuePair(Of Integer, Myclass)) = dictionaryTest.GetEnumerator() 
Questions connexes