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
Published at
2026-10-27 11:37:50 UTCEvent JSON
{
"id": "969d3442016a55550ada10c80dede2ced8c943119c0b6b82996770b8d9e8fb25",
"pubkey": "e68a0856e90d9997b1f721e905249896412dd570399a987b2e8fd5e7fcfe2279",
"created_at": 1793101070,
"kind": 1,
"tags": [
[
"t",
"tip"
]
],
"content": "Learn: Building strings in a loop\n\nA 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²).\n\nThe docs warn that many repeated changes to a string cost a lot of performance. Use a StringBuilder, then call ToString() once at the end.\n\n#tip · TIP-019",
"sig": "e2356102a8d93289b657a36260c6c0f31d182ddacd47b79acf77ebf7088eb217a388e57682aad5c3452a22fc9f74588d74396008ad829e7effa703855f095f07"
}