guoguo
9 years agoContributor
Solved
Question about value type in the dotNET.System_Collections.Hashtable()?
Hi all, In our test, we need a hashtable to store the test values. Key is string, value is array. The fDict.Add doesn't work. Does anyone know, how to use dotNET.System_Collections.Hashtable() fo...
- 9 years ago
You need to use a .NET array instead of a native JScript array.
function Test() { var fDict = dotNET.System_Collections.Hashtable().zctor(); var arr1 = ["100", "160", "200", "250", "300"]; fDict.Add("key1", JSStringArray2NETArray(arr1)); Log.Message(fDict.Item("key1").Length); // 5 Log.Message(fDict.Item("key1").Get(1).OleValue); // 160 } // Convert a JScript string array into a .NET string array. // JScript: ["a", "b", "c"] => C#: string[] {"a", "b", "c"} function JSStringArray2NETArray(JSArray) { var separator = " "; var separator2 = dotNET.System.String.Copy(separator).ToCharArray(); var str = JSArray.join(separator); var arr = dotNET.System.String.Copy(str).Split(separator2); return arr; }