I have a block which parses a list of files from S3 to get the file names.
$GetFileNamesByType = {
Param(
$fileType,
$list
)
$entryList = New-Object System.Collections.ArrayList
foreach($item in $list){
if($item.Name.Contains($fileType)){
$entryList.Add($item.Name) | Out-Null
}
}
return $entryList
}
I call this method and it returns me the following list:
2016-08-31_21-15-17_server-1.1.20558_client-1.1.20518.zip
2016-08-30_21-15-17_server-1.1.20558_client-1.1.20518.zip
2016-08-30_22-15-17_server-1.1.20558_client-1.1.20518.zip
2016-08-30_20-15-17_server-1.1.20558_client-1.1.20518.zip
2016-08-31_23-15-17_server-1.1.20558_client-1.1.20518.zip
2016-08-31_20-15-17_server-1.1.20558_client-1.1.20518.zip
2016-08-30_23-15-17_server-1.1.20558_client-1.1.20518.zip
Howerver, what I don't understand is that when I check the list type, it is an array instead of ArrayList.
foreachas an expression to generate a normal array faster than ArrayList:return foreach ($item in $list) { if($item.Name.Contains($fileType)){$item.Name} }Also,returnis optional.[Collections.ArrayList]$entryListand it'll be still faster! Well, not by much though.