cancel
Showing results for 
Search instead for 
Did you mean: 

Question about value type in the dotNET.System_Collections.Hashtable()?

SOLVED
Contributor

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() for this case? 

 

var fDict =dotNET.System_Collections.Hashtable().zctor();

var val1 = ["100", "160", "200", "250", "300"];

fDict.Add("key1", val1);

 

Best Regards,

Jie

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Moderator

Re: Question about value type in the dotNET.System_Collections.Hashtable()?

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;
}

Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️

View solution in original post

2 REPLIES 2
Highlighted
Frequent Contributor

Re: Question about value type in the dotNET.System_Collections.Hashtable()?

Hi,

   I am afraid it is not possible to use a Single key with the hashtable. You need to create a multimap hash table or pass it as a structure .

 

What is the exact requirement? You could create multiple keys dynamically and map to the values and work with it.

 

The corresponding VB script code is.

 

Set x= dotNet.System_Collections.Hashtable.zctor

val1=Array("100","160","200","250","300")

 

for i=0 to UBound(val1)

   Call x.Add("Key" & (i),val1(i))

 

Next

Highlighted
Moderator

Re: Question about value type in the dotNET.System_Collections.Hashtable()?

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;
}

Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️

View solution in original post

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors