Actually in .net strings are immutable, which means once the string variable
is created you cannot change its value. So if we are thinking that += is
actually adding some more bytes to the current string is actually a "wrong
thinking".

What happens is that a new string variable is created and then its reference
is assigned to the variable and previous string variables gets discarded.

So assume that TextBox1.Text already contains a large string. So doing a +=
will discard the previous value and will create a new value. And it will
give worst results if we are doing this repeatedly in a loop. Thats why
StringBuilder is a recommended approach in these types of scenarios.

I don't know exactly how AppendText() is working. Maybe internally it is
doing the same +=. But I think internally TextBox control is saving the
string in a more optimized way (like StringBuilder) rather putting whole
string in a single string variable. If thats true (and it should be) then
most probably AppendText() method is NOT doing the +=, it will be adding
more text like StringBuilder does.

On Thu, Nov 11, 2010 at 7:21 PM, It's time to do something <
[email protected]> wrote:

> Why textBox1.text += sometext is a very bad idea ? Even when
> "sometext" here is very short? What is the difference to
> textBox1.AppendText(...) ?

Reply via email to