小编sma*_*ele的帖子

理解.Net COM Interop中的IEnumerable

为什么我可以使用VBScript for each语句来迭代一个System.Collections.ArrayList对象,而不是一个Systems.Collections.SortedList对象?

鉴于以下内容:

set aList = Server.CreateObject("System.Collections.ArrayList")
aList.Add "a"
aList.Add "b"
aList.Add "c"
for each item in aList
    ' do something
next

set sList = Server.CreateObject("System.Collections.SortedList")
sList.Add "a", 1
sList.Add "b", 2
sList.Add "c", 3
for each item in sList
    ' do something
next
Run Code Online (Sandbox Code Playgroud)

这条线

for each item in sList
Run Code Online (Sandbox Code Playgroud)

崩溃了

object不支持此属性或方法*.

通过这个属性,我认为他们的意思是_NewEnum财产.但为什么_NewEnum被暴露ArrayList,但不是SortedList?这两个类都实现了IEnumberable从反汇编mscorelib.dll看起来是负责实现_NewEnum属性(dispId-4)的接口的接口.

如果有人能够对这些类似类的不同COM互操作行为有所了解,我将非常感激.

我知道我可以使用其他属性SortedList …

.net ienumerable com-interop

7
推荐指数
1
解决办法
793
查看次数

标签 统计

.net ×1

com-interop ×1

ienumerable ×1