2009-08-26 15 views
4

我在PowerShell中創建了一個字符串對象數組,需要將其傳遞到Xceed拉鍊庫方法,該方法需要一個字符串[],但每次都會出錯。它讓我懷疑PowerShell數組是否是.NET數組以外的東西。這裏是一些代碼:PowerShell數組是否只是.NET數組?

$string_list = @() 
foreach($f in $file_list) 
{ 
    $string_list += $f.FullName 
} 
[Xceed.Zip.QuickZip]::Zip("C:\new.zip", $true, $false, $false, $string_list) 

我得到的錯誤說:「將文件添加到zip文件時發生錯誤。」如果我的價值觀很難像這樣的代碼它的工作原理:

[Xceed.Zip.QuickZip]::Zip("C:\new.zip", $true, $false, $false, "test.txt", "test2.txt", "test3.txt") 

有人可以幫我想出解決辦法?我無法理解的區別是什麼?

編輯:我已經測試並確認我的$ string_list陣列由System.String的對象

+0

你能告訴我們的[Xceed.Zip.QuickZip] ::郵編簽名(...)? – 2009-08-26 22:12:14

+0

void Zip(String zipFileName,bool replaceExistingFiles,bool recursive,bool preservePaths,String [] filesToZip) – JimDaniel 2009-08-26 22:37:02

回答

15

如果指定:

$string_list = @() 

你給PowerShell中沒有類型信息,以便它創建System.Object的數組,它是一個可以容納任何對象的數組:

PS> ,$string_list | Get-Member 

    TypeName: System.Object[] 

嘗試指定一個特定的陣列類型(字符串數組),像這樣:

PS> [string[]]$string_list = @() 
PS> ,$string_list | Get-Member 


    TypeName: System.String[]