Join Nostr
2026-10-27 11:37:50 UTC

codementor on Nostr: Learn: Building strings in a loop A C# string can't change, so result += text creates ...

Learn: Building strings in a loop

A C# string can't change, so result += text creates a brand new string every time and copies everything so far. In a loop that adds up to O(n²).

The docs warn that many repeated changes to a string cost a lot of performance. Use a StringBuilder, then call ToString() once at the end.

#tip · TIP-019