Powershell Dictionary Array Assignment

I am trying to assign an array as a value for a dictionary entry as follows, but this is an exception to the exception.

$sd = New-Object 'System.Collections.Generic.SortedDictionary[int, string[]]' $sd[0] = "Data1a", "asda"; 

Any idea?

+4
source share
1 answer

Use the cast command for [string[]] :

 $sd = New-Object 'System.Collections.Generic.SortedDictionary[int, string[]]' $sd[0] = [string[]]("Data1a", "asda") 

Other parameters - change the type of the dictionary value to object[] :

 $sd = New-Object 'System.Collections.Generic.SortedDictionary[int, object[]]' $sd[0] = "Data1a", "asda" 
+7
source

Source: https://habr.com/ru/post/1335102/


All Articles