r/csharp•
Choicery

Does converting a variable type create a new variable in memory or replace the existing?

Help

Sorry for the basic question, complete beginner trying to understand how C# works with memory.

If I have a StringBuilder and use ToString to convert it, or change a letter with ToUpper, have I used twice as much memory or does C# replace the old variable/object with the converted version?

Obviously a couple duplicates wouldn't matter, but if I made a database program with thousands of entries that all converted to string, does it become a memory issue?

Posted Jun 23, 2025, 4:14 AM UTC

2520
Loading comments…