Get Mystery Box with random crypto!

C# Tip 𝐃𝐨𝐧'𝐭 𝐮𝐬𝐞 '+' 𝐬𝐭𝐫𝐢𝐧𝐠 𝐜𝐨𝐧𝐜𝐚𝐭𝐞𝐧𝐚𝐭𝐢𝐨𝐧 𝐢𝐧 𝐥𝐨𝐨𝐩𝐬. 𝐀 𝐬𝐭𝐫𝐢 | Learner

C# Tip

𝐃𝐨𝐧'𝐭 𝐮𝐬𝐞 '+' 𝐬𝐭𝐫𝐢𝐧𝐠 𝐜𝐨𝐧𝐜𝐚𝐭𝐞𝐧𝐚𝐭𝐢𝐨𝐧 𝐢𝐧 𝐥𝐨𝐨𝐩𝐬.

𝐀 𝐬𝐭𝐫𝐢𝐧𝐠 𝐢𝐬 𝐢𝐦𝐦𝐮𝐭𝐚𝐛𝐥𝐞.
Once we create a string, it cannot be changed.

Example:

• We have a new "Test" string - This string will take up 𝐦𝐞𝐦𝐨𝐫𝐲 𝐬𝐩𝐚𝐜𝐞 𝐨𝐧 𝐭𝐡𝐞 𝐇𝐞𝐚𝐩.
• We change the original string to "Test for string".
• We will create a 𝐧𝐞𝐰 𝐬𝐭𝐫𝐢𝐧𝐠 𝐨𝐛𝐣𝐞𝐜𝐭 𝐨𝐧 𝐭𝐡𝐞 𝐇𝐞𝐚𝐩.
• Instead of modifying the original string at the same memory address.

Doing this multiple times, modifying an existing string would cause multiple memory allocations to affect performance.

Solution is StringBuilder

The 𝐒𝐭𝐫𝐢𝐧𝐠𝐁𝐮𝐢𝐥𝐝𝐞𝐫 doesn't create a new object in the memory but 𝐝𝐲𝐧𝐚𝐦𝐢𝐜𝐚𝐥𝐥𝐲 𝐞𝐱𝐩𝐚𝐧𝐝𝐬 𝐦𝐞𝐦𝐨𝐫𝐲 to accommodate the modified string.

Source

@Abbos_Shamsiddin