VB.Net IEnumerator(Of Integer,MyClass)不可能吗?

时间:2013-07-09 00:35:05

标签: vb.net class typeof enumerator ienumerator

如何返回IEnumerator

SortedDictionary(Of Integer, MyClass)

我有这个。

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

我想要一个像

这样的功能
public function getTestEnumerator() as IEnumerator(Of Integer, MyClass)
   return dictionaryTest.GetEnumerator()
end function

IDE中生成错误 'System.Collections.IEnumerator' has no type parameters and so cannot have type arguments.

1 个答案:

答案 0 :(得分:0)

Dim dictionaryTest As New SortedDictionary(Of Integer, MyClass)

答案是替换

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

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