Loading ...

New approach to clear StringBuilder in .NET 4.0 | CodeAsp.Net

New approach to clear StringBuilder in .NET 4.0

 /5
0 (0votes)

Before .NET 4.0, if you want to clean an existing instance of  StringBuilder class, then you had to set its length equal to ZERO as there was no method to do the same. e.g.

 StringBuilder sb= new StringBuilder();

 sb.Append("hi");
 sb.AppendLine("this is samir");

 sb.Length = 0; 

 

Now in .NET 4.0, there is a method Clear to clean an instance of StringBuilder class.

sb.Clear();

 

This is a nice enhancement.

 

Comments (no comments yet)

Top Posts