经典的ASP类属性

pin*_*ger 1 vbscript asp-classic

是否可以将字典对象设置为经典ASP中类的属性?我似乎无法正确使用语法.我有一个函数,我想返回一个字典对象,并将函数返回的字典对象分配给类属性,但我不断收到类型不匹配错误?

如果我不能使用字典对象,我可以使用数组吗?

我对经典ASP很新,但我非常了解C#/ .NET.

Tes*_*101 7

这是一个简单的例子

Class TestClass
    private testDictionary

    public property get TestDict
        Set TestDict = testDictionary
    end property
    public property let TestDict(byval value)
        Set testDictionary = value
    end property
    public property set TestDict(byval value)
        Set testDictionary = value
    end property
    public function getValue(index)
        getValue = testDictionary.Item(index)
    end function
end class

'Create a Dictionary and add an entry
Set newDict = CreateObject("Scripting.Dictionary")
newDict.Add 1, "This is a test"

'Assign the dictionary to the custom object
Set mynewClass = new TestClass
mynewClass.TestDict = newDict
Set newDict = Nothing

wscript.echo mynewClass.getValue(1)

Set mynewClass = Nothing
Run Code Online (Sandbox Code Playgroud)

只需记住在处理对象时使用Set.