我可以在 VBscript 中使用 System.Collections.Generic.SortedList 吗?
我正在尝试在 VBscript 中生成排序列表,这样做:
Set GNDcons = CreateObject( "System.Collections.Generic.SortedList<string, integer>" )
但是它不起作用,我得到 Scode:800a01ad 是否可以在 VBscript 中使用这种类型?我看到 System.Collections 中还有另一个 SortedList,无法设置数据类型,但不推荐使用。
I'm trying to generate a sorted list in VBscript doing this:
Set GNDcons = CreateObject( "System.Collections.Generic.SortedList<string, integer>" )
however it doesn't work, I get Scode:800a01ad
Is it even possible to use this type in VBscript? I saw there's another SortedList in System.Collections without the possibility of setting the data types but the use was deprecated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在 VBScript 中使用 System.Collections.SortedList 类型;只需避免 System.Collections.Generic 类型和需要参数的构造函数即可。
这是一个简单的示例:
如果您想模拟键和值的类型约束,那么您可以创建一个 VBScript 包装类。例如:
注意:上面的包装类尚未经过 100% 测试,但确实将键限制为 Variant 字符串子类型,将值限制为 Variant 整数子类型。生成的列表会自动按键排序。
输出:
You can use the
System.Collections.SortedList
type in VBScript; just avoid theSystem.Collections.Generic
types, and constructors requiring parameters.Here's a simple example:
If you want to simulate type constraints for keys and values, then you can create a VBScript wrapper class. For example:
Note: The above wrapper class has not been 100% tested, but does restrict keys to Variant string subtypes, and values to Variant integer subtypes. The resulting list is automatically sorted by keys.
Output: