2011-01-11 10 views
4

다음과 같이 사전을 값으로 배열을 지정하려고하는데 예외가 발생했습니다.Powershell의 사전 항목에 배열 할당

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

어떤 아이디어가 있습니까? !

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

또 다른 옵션은 object[]에 사전 값 유형을 변경하는 것입니다 :

답변

7

사용 [string[]] 캐스팅

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

화려한 ... 내가 유 언급처럼 캐스팅하려하지만 난 누락 된 둥근 괄호. 감사합니다 – nabeelfarid

+0

훌륭한 작품. 나는 두 번째 발췌 문장을 훨씬 더 좋아한다. 주조는 먼지입니다. D – Guy