Bird
0
0

Why does StringBuilder provide better performance than string concatenation in loops?

hard🧠 Conceptual Q10 of 15
C Sharp (C#) - Strings and StringBuilder
Why does StringBuilder provide better performance than string concatenation in loops?
ABecause StringBuilder modifies the same buffer without creating new strings
BBecause StringBuilder uses multithreading internally
CBecause string concatenation is optimized by the compiler
DBecause StringBuilder stores strings in a database
Step-by-Step Solution
Solution:
  1. Step 1: Understand string immutability

    Strings are immutable; concatenation creates new strings each time, causing overhead.
  2. Step 2: Understand StringBuilder internal behavior

    StringBuilder uses a mutable buffer, modifying it in place without creating new objects, improving speed.
  3. Final Answer:

    Because StringBuilder modifies the same buffer without creating new strings -> Option A
  4. Quick Check:

    Mutable buffer = better performance [OK]
Quick Trick: StringBuilder avoids new string creation on each change [OK]
Common Mistakes:
MISTAKES
  • Thinking StringBuilder uses threads
  • Believing compiler optimizes concatenation fully

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Sharp (C#) Quizzes