Don’t do that #15: Use Add method when creating an array with multiple elements
Don’t do that: An empty array is created and then the elements are added.
1 2 3 4 5 6 7 |
$array = @() $array += 'User1' $array += 'User2' $array += 'User3' $array += 'User4' $array += 'User5' |
Do that: There are several ways to do that with one-liners:
1 2 3 4 5 |
$array = @('User1', 'User2', 'User3', 'User4', 'User5') $array = 'User1', 'User2', 'User3', 'User4', 'User5' $array = 'User1,User2,User3,User4,User5'.Split(',') $array = .{$args} User1 User2 User3 User4 User5 $array = echo User1 User2 User3 User4 User5 # echo is an alias |