开发者

Dictionary object syntax?

I'm having trouble figuring out the syntax for a JScript .NET dictionary object. I have tried

private var myDict开发者_如何学JAVAionary: Dictionary<string><string>;

but the compiler complains that it's missing a semicolon and that the Dictionary object is not declared.

I know JScript does have a native dictionary-like object format, but I'm not sure if there are disadvantages to using it instead of the .NET-specific construct. I.e., what if someone wants to extend my script using another .NET language?


JScript.Net doesn't support generic types and methods.

Check this link:

http://msdn.microsoft.com/en-us/library/xfhwa508(v=VS.80).aspx

Click on the JScript Tab under Syntax heading.


There is One way to use the Dictionary Type in JScript.Net

Create a c# assembly

using System;
using System.Collections.Generic;
using System.Text;

namespace Sample
{
    class Tools
    {
        public Dictionary<string,object> Dict()
        {
            return new Dictionary<string,object>();
        }
    }
}

IN JScript

import System;
import System.Text;

package Sample
{
    public class Main
    {
        public var MyDictionary = Tools.Dict();

        function Main()
        {
            MyDictionary["test"] = "Works";
            Console.WriteLine(MyDictionary["test"]);
        }
    }
}

FTW so you can use c# assembly with your JScript.net stuff

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜