String vs StringBuilder in C# – Interview & Real-World Insight
- In C#, choosing between string and StringBuilder can significantly impact performance and memory usage.
- string is immutable – every modification creates a new object
- StringBuilder is mutable – changes happen in the same memory buffer
Rule of thumb:
- Use string for small, fixed text
- Use StringBuilder for frequent modifications like loops, logs, or dynamic SQL Understanding these internals not only helps in writing optimized code but also makes a strong impression in technical interviews.