Thursday, April 11, 2013

string and stringbuilder in .net


String is immutable suppose there is a string object and it has a assigned value to it so whenever we reassign any value to that string object or append new string to it will again create a new memory allocation for that same object. Thus every-time a new string gets created.


String builder is mutable that means reassigning value to a stringbuilder object doesn't create a space for new memory allocation as it works on the preallocated memory itself. Thus reducing memory overhead. And Will boost performance where we want to con-cat many strings.


Example :


No comments:

Post a Comment