Bird
0
0

Why does using += to add elements to a large object array in PowerShell cause performance issues?

hard📝 Conceptual Q10 of 15
PowerShell - Working with Objects
Why does using += to add elements to a large object array in PowerShell cause performance issues?
ABecause += modifies the original array in place
BBecause arrays are fixed size and += creates a new array each time
CBecause += only works with strings
DBecause += deletes the array before adding
Step-by-Step Solution
Solution:
  1. Step 1: Understand array resizing behavior

    PowerShell arrays are fixed size; += creates a new array copying old elements plus new one.
  2. Step 2: Explain performance impact

    Repeated += causes many array copies, slowing performance on large arrays.
  3. Final Answer:

    Because arrays are fixed size and += creates a new array each time -> Option B
  4. Quick Check:

    += creates new array each time = B [OK]
Quick Trick: += creates new array; avoid in large loops [OK]
Common Mistakes:
  • Thinking += modifies array in place
  • Believing += only works with strings
  • Assuming += deletes array before adding

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes