Why does $dlls.Count
return a single element? I try to declare my array of strings as such:
$basePath = Split-Path $MyInvocation.MyCommand.Path
$dlls = @(
$basePath + "\bin\debug\dll1.dll",
$basePath + "\bin\debug\dll2.dll",
$basePath + "\bin\debug\dll3.dll"
)
You can also initialize the String Array as follows:String[] strArray = new String[3]; strArray[0] = “one”; strArray[1] = “two”; strArray[2] = “three”; Here the String Array is declared first. Then in the next line, the individual elements are assigned values.
PowerShell array of strings is the collection of string objects that is multiple strings are residing into the same collection which can be declared using String[], @() or the ArrayList and can be used in various ways like functions, in the file content, as a variable and can perform the multiple operations on the ...
Use """ (double quote) or ''' (single quote) for multiline string or use \ for seperating them. NOTE: """ and ''' should be used with care otherwise it may print too many spaces in between two lines.
If we declare a fixed array of char using the [] notation, then we can store a string consisting of the same number of characters in that location. Note that one extra character space for the terminating null byte should be considered when copying the character string to the array location.
You should use something like:
$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")
)
As your answer shows, the semicolons also work because that marks the end of a statement...that would be evaluated, similar to using parenthesis.
Alternatively, use another pattern like:
$dlls = @()
$dlls += "...."
But then you might want to use ArrayList and gain performance benefits...
See PowerShell array initialization
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With