This should hopefully be a quick one. I have a StringBuilder like so:
StringBuilder sb = new StringBuilder();
I append to my StringBuilder like so:
sb.Append("Foo");
sb.Append("Bar");
I then want to make this equal to a string variable. Do I do this like so:
string foobar = sb;
Or like so:
string foobar = sb.ToString();
Is the former being lazy or the latter adding more code than is necessary?
Thanks
ToString()
off when calling. At worst the overload will call it for you and at best it might have some clever optimisation. But either way the language designers added the overload for your benefit, so might as well use it. – ArchieStreamWriter
to astring
either. And calling.ToString()
wont give you the content of the writer. – PericraniumStreamWriter.Write(object value)
method. With aStringBuilder
as hisvalue
. – Archie