Interview Question

string vs StringBuilder?

Use string for immutable text and StringBuilder for repeated edits.

💡 Concept ✅ Quick Revision 🔷 C#

Answer

string is immutable, while StringBuilder maintains a mutable character buffer. • Changing a string expression creates a new string result. • StringBuilder can reduce temporary allocations during many incremental modifications. • For a small fixed number of concatenations, normal string operations are often clearer.

💡 C# Example

var builder = new System.Text.StringBuilder(); builder.Append("Hello"); builder.Append(' '); builder.Append("C#"); Console.WriteLine(builder.ToString());

Output

Hello C#

⚡ Quick Revision

Use string for immutable text and StringBuilder for repeated edits.