StringBuilder.Clear in help but not in ide

M

mp

Hi,
according to help
(http://msdn.microsoft.com/en-us/library/system.text.stringbuilder.aspx)
there's a .Clear method on the string builder object to empty the contents.
I don't get that in my ide.
StringBuilder lastLine = new StringBuilder();
....fill in lastLine then try to clear it...
lastLine.Clear();
....produces this error
Error 1 'System.Text.StringBuilder' does not contain a definition for
'Clear' and no extension method 'Clear' accepting a first argument of type
'System.Text.StringBuilder' could be found (are you missing a using
directive or an assembly reference?)

if there's not a .Clear method, how to empty and reuse a StringBuilder?

I have a loop and I fill a StringBuilder via .Append,
then i read it at some point(via .ToString()),
then want to clear it and start a new one...
can I just create a new reference? and does that automatically "discard" the
previous reference?

StringBuilder lastLine = new StringBuilder();
....using in some loop...
do {
lastLine.Append ("something");
//at some point i'm done with this one
//do something with lastLine.ToString();

//now i want a new blank stringBuilder...do i just re-create one?
lastLine = new StringBuilder();
//or should i empty the existing one?
lastLine.Remove(0, lastLine.Length - 1);

....continue processing...
} (until Done;)


thanks
mark
 
M

mp

Jason Keats said:
That's because you're not using .NET 4. Try clicking 'Other Versions' at
the top of the page.

Try setting Length = 0, instead.

ah ha!
thanks
mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top