VB.Net IEnumerator(整数,MyClass)不可能?

VB.Net IEnumerator(整数,MyClass)不可能?,vb.net,class,typeof,enumerator,ienumerator,Vb.net,Class,Typeof,Enumerator,Ienumerator,如何返回SortedDictionary(整数,MyClass)的IEnumerator 我有这个 Dim dictionaryTest As New SortedDictionary(Of Integer, MyClass) Dim enumerator As IEnumerator(Of Integer, MyClass) = dictionaryTest.GetEnumerator() '<- not possible. 在IDE中生成错误 “System.Collections.

如何返回
SortedDictionary(整数,MyClass)的
IEnumerator

我有这个

Dim dictionaryTest As New SortedDictionary(Of Integer, MyClass)
Dim enumerator As IEnumerator(Of Integer, MyClass) = dictionaryTest.GetEnumerator() '<- not possible.
在IDE中生成错误
“System.Collections.IEnumerator”没有类型参数,因此不能有类型参数。

Dim dictionaryTest As New SortedDictionary(Of Integer, MyClass)
答案是替换

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

您是否导入了
System.Collections.Generic
命名空间?另外,我相信它实际上是一个
IEnumerator(属于KeyValuePair(属于Integer,Myclass))
工作得非常完美。我缺少的是KeyValuePair(…)的
。奇怪的是,为什么我不必对
SortedDictionary
使用
KeyValuePair
,但我需要它来处理
GetEnumerator()
。我把它放在
IEnumerator
上,它似乎也能工作,但还没有导入
系统.Collections.Generic
仍然没有编译器错误或警告。我想,我不需要那个库,
导入系统。集合
可以工作,但可能我正在导入所有东西,不确定有两个
IEnumerable
接口-通用
IEnumerable(Of t)
和非通用
IEnumerable
。IIRC前者在
System.Collections.Generic
中,后者在
System.Collections中
至于
KeyValuePair
我不确定为什么在顶部示例中不需要它,VB一定在幕后做了一些可爱的事情。我很确定这个样本在C语言中不起作用。
Dim enumerator As IEnumerator(Of Integer, MyClass) = dictionaryTest.GetEnumerator() '<- not possible.
Dim enumerator As IEnumerator(Of KeyValuePair(Of Integer, Myclass)) = dictionaryTest.GetEnumerator()