PowerShell - Working with ObjectsWhy does using += to add elements to a large object array in PowerShell cause performance issues?ABecause += modifies the original array in placeBBecause arrays are fixed size and += creates a new array each timeCBecause += only works with stringsDBecause += deletes the array before addingCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand array resizing behaviorPowerShell arrays are fixed size; += creates a new array copying old elements plus new one.Step 2: Explain performance impactRepeated += causes many array copies, slowing performance on large arrays.Final Answer:Because arrays are fixed size and += creates a new array each time -> Option BQuick Check:+= creates new array each time = B [OK]Quick Trick: += creates new array; avoid in large loops [OK]Common Mistakes:Thinking += modifies array in placeBelieving += only works with stringsAssuming += deletes array before adding
Master "Working with Objects" in PowerShell9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More PowerShell Quizzes Error Handling - Error logging patterns - Quiz 4medium Functions - Default parameter values - Quiz 9hard Functions - Parameters - Quiz 1easy Functions - Return values - Quiz 14medium Functions - Advanced functions (CmdletBinding) - Quiz 6medium Modules and Script Organization - Module creation basics - Quiz 7medium Modules and Script Organization - Installing modules (Install-Module) - Quiz 11easy Modules and Script Organization - Module creation basics - Quiz 10hard Regular Expressions - Why regex enables pattern matching - Quiz 6medium Regular Expressions - Regex quantifiers and anchors - Quiz 4medium