为什么$dlls.Count
只返回一个元素?我试图声明我的字符串数组如下:
$basePath = Split-Path $MyInvocation.MyCommand.Path
$dlls = @(
$basePath + "\bin\debug\dll1.dll",
$basePath + "\bin\debug\dll2.dll",
$basePath + "\bin\debug\dll3.dll"
)
为什么$dlls.Count
只返回一个元素?我试图声明我的字符串数组如下:
$basePath = Split-Path $MyInvocation.MyCommand.Path
$dlls = @(
$basePath + "\bin\debug\dll1.dll",
$basePath + "\bin\debug\dll2.dll",
$basePath + "\bin\debug\dll3.dll"
)
你应该使用类似于以下的内容:
$dlls = @(
($basePath + "\bin\debug\dll1.dll"),
($basePath + "\bin\debug\dll2.dll"),
($basePath + "\bin\debug\dll3.dll")
)
or
$dlls = @(
$($basePath + "\bin\debug\dll1.dll"),
$($basePath + "\bin\debug\dll2.dll"),
$($basePath + "\bin\debug\dll3.dll")
)
正如您的回答所示,分号也起作用,因为它标志着语句的结尾......这将被评估,类似于使用括号。
或者,可以使用另一种模式,例如:
$dlls = @()
$dlls += "...."
但是你可能想要使用ArrayList并获得性能上的好处...
我发现,我必须使用分号而不是逗号……有人能解释一下为什么吗?
根据几乎任何来源(例如此网站)都清楚地表明要使用逗号。
$basePath = Split-Path $MyInvocation.MyCommand.Path
$dlls = @(
$basePath + "\bin\debug\dll1.dll";
$basePath + "\bin\debug\dll2.dll";
$basePath + "\bin\debug\dll3.dll";
)
$basePath = Split-Path $MyInvocation.MyCommand.Path
$dllDir = "$basePath\bin\debug"
$dlls = `
"$dllDir\dll1.dll",
"$dllDir\dll2.dll",
"$dllDIr\dll3.dll"
在声明dlls
变量之后的反引号只是对换行字符的转义,仅用于提高可读性。