سؤال

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

private var myDictionary: 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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top